Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo2 {
  4.  
  5.  
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. int n = scanner.nextInt();
  9. for (int i = 1; i <= n; i++) {
  10. boolean isOdd = false;
  11. int sum = 0;
  12. int num = i;
  13.  
  14. for (int e = 0; e < i; e++) {
  15. sum += num % 10;
  16. num /= 10;
  17. if (num % 2 != 0) {
  18. isOdd = true;
  19. }
  20. }
  21.  
  22. if (sum % 8 == 0 && isOdd) {
  23. System.out.println(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