Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package palindrome;
- /**
- *
- * @author Gaby
- */
- import java.util.Scanner;
- public class Palindrome {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner imput = new Scanner(System.in);
- System.out.println("Enter your word");
- String word = imput.next();
- boolean a = true;
- for ( int i = 0; i < word.length(); i++) {
- if (word.charAt(i) != word.charAt(word.length() - i - 1)){
- a = false; break;
- } else{
- a = true;
- }
- }
- if (a == true){
- System.out.println("The word " + word + " is a palindrome");
- } else{
- System.out.println("The word " + word + " is not a palindrome");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement