-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrange_Size.java
More file actions
45 lines (45 loc) · 1.05 KB
/
Copy pathArrange_Size.java
File metadata and controls
45 lines (45 loc) · 1.05 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
import java.util.Scanner;
import java.util.*;
class Arrange_Size
{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter string :");
String s = sc.nextLine();
String w="",sent="";
StringTokenizer st=new StringTokenizer(s);
int n=st.countTokens(); String a[]=new String[n];
int i=0;
while(st.hasMoreTokens())
{
w=st.nextToken();
a[i]=w;
i++;
}
String temp;
for (int j = 0; j < n - 1; j++)
{
for (int k = j + 1; k < n; k++)
{
if (a[j].length()>a[k].length())
{
temp = a[j];
a[j] = a[k];
a[k] = temp;
}
else if (a[j].length()==a[k].length()){
if (a[j].compareTo(a[k])>0)
{
temp = a[j];
a[j] = a[k];
a[k] = temp;
}
}
}
}
System.out.println("Sorted string is :");
for(i=0;i<n;i++){
System.out.print(a[i]+" ");
}
}
}