Repository navigation
Expand file tree
/
Copy pathpotential.java
More file actions
82 lines (73 loc) · 2.11 KB
/
Copy pathpotential.java
File metadata and controls
82 lines (73 loc) · 2.11 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
import java.util.*;
class potential
{
int poten(String s)
{
int p=0;
for(int i=0;i<s.length();i++)
{
p=p+(int)s.charAt(i);
}
return p;
}
public void main ()
{
Scanner Sc=new Scanner (System.in);
System.out.println("enter your sentence");
String a=Sc.nextLine();
int word=0;
char m=a.charAt(a.length()-1);
if((m=='!')||(m=='?')||(m=='.'))
{
for(int i=0;i<a.length();i++)
{
if((a.charAt(i)=='!')||(a.charAt(i)=='?')||(a.charAt(i)=='.')||(a.charAt(i)==' '))
{
word+=1;
}
}
String ar[]=new String[word];
int arr[]=new int[word];
String words="";
int t=0;
for(int i=0;i<a.length();i++)
{
if((a.charAt(i)=='!')||(a.charAt(i)=='?')||(a.charAt(i)=='.')||(a.charAt(i)==' '))
{
ar[t]=words;
arr[t]=poten(words);
words="";
t++;
}
else
{
words=words+a.charAt(i);
}
}
for(int i=0;i<arr.length-1;i++)
{
for(int j=i+1;j<arr.length;j++)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
String tempo;
tempo=ar[i];
ar[i]=ar[j];
ar[j]=tempo;
}
}
}
for(int i=0;i<ar.length;i++)
{
System.out.println(ar[i]+"="+arr[i]);
}
}
else
{
System.out.println("invalid");
}
}
}