Monday, 6 June 2016

Chapter 3 Exercise 12, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

3.12 (Palindrome number) Write a program that prompts the user to enter a three-digit integer and 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:


import java.util.Scanner;
 
public class ProgrammingEx3_12 {
 
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
 
  System.out.print("Enter a three-digit integer:");
  int number = input.nextInt();
 
  // Extracting digits
  int first = number / 100;
  int last = number % 10;
  if (last == first) {
   System.out.print(number + " is a palindrome");
  } else {
   System.out.print(number + " is not a palindrome");
  }
 
 }
 
}

3 comments :

  1. (Palindrome number) Write a program that prompts the user to enter a three-digit
    integer and 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:

    ReplyDelete
  2. (Palindrome number) Write a program that prompts the user to enter a three-digit
    integer and 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:

    ReplyDelete