Advertisement
veronikaaa86

10. Special Numbers

May 25th, 2022
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package dataTypesAndVariables;
  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.  
  15. while (currentNum > 0) {
  16. sum = sum + (currentNum % 10);
  17. currentNum = currentNum / 10;
  18. }
  19.  
  20. if (sum == 5 || sum == 7 || sum == 11) {
  21. System.out.printf("%d -> True%n", i);
  22. } else {
  23. System.out.printf("%d -> False%n", i);
  24. }
  25. }
  26. }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement