Advertisement
meteor4o

Java-Fund-DataLab- 10.SpecialNumbers

May 29th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SpecialNumbers {
  6. public static void main(String[] args) {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. int n = sc.nextInt();
  11. boolean isSpecial = false;
  12. int sum = 0;
  13.  
  14. for (int num = 1; num <= n; num++) {
  15. int numA = num;
  16.  
  17.  
  18. while (numA > 0) {
  19. int digit = numA % 10;
  20. sum += digit;
  21. numA = numA / 10;
  22. }
  23. if (sum == 5 || sum == 7 || sum == 11) {
  24. isSpecial = true;
  25. System.out.printf("%d -> True%n", num);
  26. } else {
  27. System.out.printf("%d -> False%n", num);
  28. }
  29. isSpecial = false;
  30. sum = 0;
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement