Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section A- conditional clause
- Ex4: identical digit in a trio-digit number
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int number;
- int tmp; //keeping the number intact
- byte digit;
- Scanner s=new Scanner(System.in);
- //user input: we can assume the input is valid
- System.out.println("Enter a Trio-digit number: ");
- number=s.nextInt();
- tmp=number/10;
- digit= (byte) (number%10);
- //check digits display message
- if(digit==tmp%10 && tmp/10==digit)
- System.out.println("Identical Trio digits");
- else
- System.out.println("NOT identical");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment