-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPotential.java
More file actions
94 lines (90 loc) · 2.18 KB
/
Copy pathPotential.java
File metadata and controls
94 lines (90 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.util.*;
class Potential
{
String s;
int l;
int arr[];
String arr1[];
Potential(String st,int len)
{
s=st;
l=len;
arr=new int[l];
arr1=new String[l];
}
int potent(String st)
{
int len=st.length();
int pot=0;
for(int i=0;i<len;i++)
{
pot=(int)st.charAt(i)+pot;
}
return pot;
}
void arrange()
{
for(int i=0;i<l;i++)
{
for(int j=i+1;j<l-1;j++)
{
int k=0;
String s2="";
if(arr[i]>arr[j])
{
k=arr[i];
s2=arr1[i];
arr[i]=arr[j];
arr1[i]=arr1[j];
arr[j]=k;
arr1[j]=s2;
}
}
}
}
void display()
{
for(int i=0;i<l;i++)
{
System.out.print(arr1[i]+" ");
}
System.out.println(s.charAt(s.length()-1));
}
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the String");
String s=Sc.nextLine();
String s5=s.substring(0,s.length()-1);
StringTokenizer st=new StringTokenizer(s5);
int len=st.countTokens();
Potential ob=new Potential(s,len);
int i1=0;
if(((s.charAt(s.length()-1))=='.')||((s.charAt(s.length()-1))=='!')||((s.charAt(s.length()-1))=='?'))
{
while(st.hasMoreTokens())
{
String s1=st.nextToken();
int l=s1.length();
int count=0;
for(int i=0;i<l;i++)
{
if(Character.isUpperCase(s.charAt(i)))
count++;
}
if(count==l)
{
int pot=ob.potent(s1);
ob.arr[i1]=pot;
ob.arr1[i1]=s1;
i1++;
}
}
ob.display();
ob.arrange();
ob.display();
}
else
System.out.println("INVALID INPUT");
}
}