Java Arithmetic Operators Modulus Operator find three digit palindrome number

Question

We would like to write a program that prompts the user to enter a three-digit integer.

Determines whether it is a palindrome number.

A number is palindrome if it reads the same from right to left and from left to right.

Here is a sample run of this program:

Enter a three-digit integer: 121 
121 is a palindrome 

Enter a three-digit integer: 123 
123 is not a palindrome 
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    //from w  ww.j a va 2s  .  c  om
    System.out.print("Enter a three-digit integer: ");
    int number = input.nextInt();

    //your code here
  }
}


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    
    System.out.print("Enter a three-digit integer: ");
    int number = input.nextInt();

    if (number / 100 == number % 10)
      System.out.println(number + " is a palindrome");
    else 
      System.out.println(number + " is not a palindrome");
  }
}



PreviousNext

Related