Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170629;
- import java.util.Scanner;
- public class WhileSlide29Ex05 {
- public static void main(String[] args) {
- /*
- * קלוט מהמשתמש מספר והצג האם כל ספרותיו זהות
- */
- // create a scanner
- Scanner s = new Scanner(System.in);
- int n; // input: integer value
- do {
- // ask for input
- System.out.print("Enter a positive integer number: ");
- // get and save input number
- n = s.nextInt();
- } while (n < 0); // be sure that n is positive
- // close scanner
- s.close();
- int digit = n % 10; // calculated: first digit of the number
- int tmp = n / 10; // calculated: other digits to be checked
- while (tmp > 0) {
- if (tmp % 10 != digit) {
- break; // stop: in this case tmp>0
- }
- tmp /= 10; // continue to next digit
- }
- System.out.printf("digits of the number %d are %sthe same!", n,
- tmp > 0 ? "not " : "");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement