-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion4.java
More file actions
52 lines (39 loc) · 1.25 KB
/
Copy pathquestion4.java
File metadata and controls
52 lines (39 loc) · 1.25 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
import java.util.Scanner;
import java.lang.String;
public class question4
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in) ;
String arr [] = new String [5] ;
for (int i = 0 ; i < 5 ; i++)
{
System.out.print("Word " + (i+1) + ":");
String word = input.nextLine();
arr [i] = word ;
}
System.out.print("\n");
for (int i = 0 ; i < 5 ; i++)
{
char duplicate [] = arr[i].toCharArray() ;
int length = duplicate.length ;
int j = 0 ;
for (int k = (length - 1); k >= 0; k--)
{
duplicate [k] = arr[i].charAt(j) ;
j++ ;
}
// Convert char array back to the original string
String check = new String(duplicate) ;
//System.out.println("Reversed String: " + str) ;
if (check.equals(arr[i]))
{
System.out.println("Word" + (i+1) + " is a Palandrome") ;
}
else
{
System.out.println("Word" + (i+1) + " is NOT a Palandrome") ;
}
}
}
}