hpilo

Chapter2_SyntaxA_Ex4

Dec 15th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.       Chapter 2: Syntax section A- conditional clause
  5.  
  6.         Ex4: identical digit in a trio-digit number
  7.     ===================================================
  8.  */
  9.  
  10.  
  11. public class MyProgram {
  12.     public static void main(String[] args) {
  13.  
  14.         //variables
  15.         int number;
  16.         int tmp;        //keeping the number intact
  17.         byte digit;
  18.         Scanner s=new Scanner(System.in);
  19.  
  20.  
  21.         //user input:   we can assume the input is valid
  22.         System.out.println("Enter a Trio-digit number: ");
  23.         number=s.nextInt();
  24.         tmp=number/10;
  25.         digit= (byte) (number%10);
  26.  
  27.         //check digits display message
  28.         if(digit==tmp%10 && tmp/10==digit)
  29.             System.out.println("Identical Trio digits");
  30.         else
  31.             System.out.println("NOT identical");
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment