Advertisement
veronikaaa86

10. Special Numbers

Sep 21st, 2022
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 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 n = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int i = 1; i <= n; i++) {
  12.             int currentNum = i;
  13.             int sum = 0;
  14.             while (currentNum > 0) {
  15.                 sum = sum + (currentNum % 10);
  16.                 currentNum = currentNum / 10;
  17.             }
  18.  
  19.             if (sum == 5 || sum == 7 || sum == 11) {
  20.                 System.out.printf("%d -> True%n", i);
  21.             } else {
  22.                 System.out.printf("%d -> False%n", i);
  23.             }
  24.         }
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement