Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Palindrome{
- private static String getInput(String prompt){
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- System.out.print(prompt);
- System.out.flush();
- try{
- return stdin.readLine();
- }catch(Exception e){
- return "Error: " + e.getMessage();
- }
- }
- static public void main (String[] args){
- String input = getInput("Enter a string: ");
- int length = input.length();
- for(int i=0; i<length/2; i++){
- if(input.charAt(i) != input.charAt(length - 1 - i)){
- System.out.println("It's not a Palindrome!");
- return;
- }
- }
- System.out.print("It's a Palindrome!");
- }
- }
- // Output:-
- // C:\Java>java Palindrome
- // Enter a string: dad
- // It's a Palindrome!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement