Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
63 lines (60 loc) · 1.26 KB

File metadata and controls

63 lines (60 loc) · 1.26 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package String;
public class LargeWordCount {
public static String[] split(String s) {
int c = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ')
c++;
}
String[] temp = new String[c + 1];
String t = "";
int i=0;
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) != ' ') {
t += s.charAt(j);
} else {
temp[i++] = t;
t = "";
}
}
temp[i] = t;
return temp;
}
public static void sort(String[] s) {
for(int j=0;j<s.length;j++) {
for(int i=0;i<s.length-(j+1);i++) {
if(s[i].length()>s[i+1].length()) {
String t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
}
}
}
public static String sortAndCount(String[] sp) {
sort(sp);
String sx="";
int n;
for(int k=0;k<sp.length-1;k++) {
if(sp[k].length()!=sp[k+1].length()) {
n=sp[k].length();
sx+=sp[k]+n+" ";
}else {
sx+=sp[k]+" ";
}
}
sx+=sp[sp.length-1]+sp[sp.length-1].length();
return sx;
}
public static void main(String[] args) {
String s = "the white tiger is bigger than the brown tiger";
// output : is 2 the 3 than 4 white tiger brown 5 bigger 6
String[] sp=split(s);
for(String n:sp) {
System.out.print(n+" ");
}
System.out.println();
String res=sortAndCount(sp);
System.out.println(res);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.