Advertisement
Guest User

SpecialNumbers2

a guest
Mar 30th, 2020
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SpecialNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         for (int num = 1; num <= n; num++) {
  8.             int sumOfDigits = 0;
  9.             int digits = num;
  10.             while (digits > 0) {
  11.                 sumOfDigits += digits % 10;
  12.                 digits = digits / 10;
  13.             }
  14.  
  15.             if (sumOfDigits == 5 || sumOfDigits == 7 || sumOfDigits == 11) {
  16.                 System.out.printf("%d -> True%n", num);
  17.             } else {
  18.                 System.out.printf("%d -> False%n", num);
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement