Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /* ==================================================
- Chapter 2: Syntax section B- Loops
- Ex5: Identical digits (two digit number)
- ===================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int number;
- boolean loop=false; //represent identical digits
- Scanner s=new Scanner(System.in);
- while(!loop){
- System.out.println("Enter a two digit number: ");
- number=s.nextInt(); //we can assume valid input
- //if identical, break the loop
- if(number%10==number/10)
- break;
- /*
- //option 2:
- if(number%10==number/10)
- loop=true;
- */
- }
- System.out.println("Identical digits!\n***End***");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment