-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_in_File.java
More file actions
33 lines (33 loc) · 900 Bytes
/
Copy pathPalindrome_in_File.java
File metadata and controls
33 lines (33 loc) · 900 Bytes
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
import java.util.*;
import java.io.*;
class Palindrome_in_File{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
try{
System.out.println("Enter the String : ");
String s=sc.nextLine();
FileWriter fw=new FileWriter("file1.txt");
fw.write(s);
fw.close();
char ch[]=new char[1000];
FileReader fr=new FileReader("file1.txt");
fr.read(ch);
fr.close();
sc.close();
String s1,s2="";
s1=String.valueOf(ch);
int n=s1.length();
for(int i=n-1;i>=0;i--)
s2+=s1.charAt(i);
System.out.println("s1:"+s1);
System.out.println("s2:"+s2);
if(s1.equals(s2)==true){
System.out.println(s1+" is a Palindrome");
}
else
System.out.println(s1+" is not a Palindrome");
}catch(Exception e){
System.out.println(e);
}
}
}