Advertisement
Guest User

Untitled

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