Advertisement
veronikaaa86

10. Special Numbers

Jan 18th, 2023
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package dataTypes;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P10SpecialNumbers {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int num = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int i = 1; i <= num; i++) {
  12.             int currentNum = i;
  13.  
  14.             int sum = 0;
  15.             while (currentNum > 0) {
  16.                 sum = sum + (currentNum % 10);
  17.                 currentNum = currentNum / 10;
  18.             }
  19.  
  20.             boolean isSpecial = sum == 5 || sum == 7 || sum == 11;
  21.  
  22.             if (isSpecial) {
  23.                 System.out.printf("%d -> True%n", i);
  24.             } else {
  25.                 System.out.printf("%d -> False%n", i);
  26.  
  27.             }
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement