Advertisement
Guest User

Untitled

a guest
Jun 11th, 2019
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. package JavaFundamentalsMay2019;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MethodsAndFunctionsExcercise {
  6.  
  7. static boolean devisibleByEigth(int num) {
  8.  
  9. int sum = 0;
  10. while (num > 0) {
  11. sum += num % 10;
  12. num /= 10;
  13. }
  14. if (sum % 8 == 0) {
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. }
  20.  
  21. static boolean oddDigit(int num) {
  22.  
  23. int counter = 0;
  24. while (num > 0) {
  25. if ((num % 10) % 2 == 1) {
  26. counter++;
  27. }
  28. num /= 10;
  29. }
  30. if (counter >= 1) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }
  36.  
  37. public static void main(String[] args) {
  38. Scanner scanner = new Scanner(System.in);
  39.  
  40. int num = Integer.parseInt(scanner.nextLine());
  41.  
  42. for (int i = 1; i <= num ; i++) {
  43. if (devisibleByEigth(i) && oddDigit(i)) {
  44. System.out.println(i);
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement