-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalinSort.java
More file actions
55 lines (55 loc) · 1.13 KB
/
PalinSort.java
File metadata and controls
55 lines (55 loc) · 1.13 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
import java.util.*;
class PalinSort {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String []str = new String[10];//Creating an array str
String []rev = new String[10];//Creating an array rev
int loc[] = new int[10];//Creating an array loc
int size[] = new int [10];//Creating an array size
int id = 0;
int temp = 0;
for(int i=0;i<10;i++)
{
System.out.println("Enter a string");
str[i] = sc.nextLine();
rev[i] = "";
for(int j=str[i].length()-1;j>=0;j--)
{
rev[i] = rev[i] + str[i].charAt(j);
}
}
for(int i=0;i<10;i++)
{
if(str[i].equals(rev[i]))
{
loc[id]=i;
id+=1;
}
}
for(int i=0;i<id;i++)
{
size[i] = str[loc[i]].length();
}
for(int i=0;i<id;i++)
{
for(int j=0;j<id-1;j++)
{
if(size[j]<size[j+1])
{
temp = size[j];
size[j] = size[j+1];
size[j+1] = temp;
temp = loc[j];
loc[j] = loc[j+1];
loc[j+1] = temp;
}
}
}
System.out.println("Palindrome Strings are");
for(int i=0;i<id;i++)
{
System.out.println(str[loc[i]]);
}
}
}