-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPot.java
More file actions
81 lines (78 loc) · 1.81 KB
/
Copy pathPot.java
File metadata and controls
81 lines (78 loc) · 1.81 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
import java .util.*;
class Pot
{
String st;
int len;
int arr[];
String word[];
int check=0;
Pot(String s,int l)
{
st=s;
len=l;
arr=new int [len];
word=new String[len];
}
public void potential(String s)
{
int sum=0;
int l=s.length();
for(int i=0;i<l;i++)
{
sum=sum+(int)s.charAt(i);
}
System.out.println(s+":: "+sum);
arr[check]=sum;
word[check]=s;
check++;
}
public void sort()
{
for(int i=0;i<len;i++)
{ int d=0;
String s="";
for(int j=0;j<len;j++)
{
if(arr[i]<arr[j])
{
d=arr[i];
s=word[i];
arr[i]=arr[j];
word[i]=word[j];
arr[j]=d;
word[j]=s;
}
}
}
System.out.print("OUTPUT:: ");
for(int i=0;i<len;i++)
{
System.out.print(word[i]+" ");
}
System.out.println();
}
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the Sentence");
String s1=Sc.nextLine();
int len=s1.length();
char ch=s1.charAt(len-1);
if((ch=='?')||(ch=='.')||(ch=='!'))
{
String st=s1.substring(0,len-1);
System.out.println(st);
StringTokenizer s=new StringTokenizer(st);
int c=s.countTokens();
Pot ob=new Pot(st,c);
while(s.hasMoreTokens())
{
String w=s.nextToken();
ob.potential(w);
}
ob.sort();
}
else
System.out.println ("INVALID STRING");
}
}