SHARE
TWEET

Untitled

a guest Oct 18th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class lec4zad10 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int num = Integer.parseInt(scanner.nextLine());
  7.         for (int i = 1; i <= num; i++) {
  8.             if (checkIfTheSumOfDigitsIsDivisibleBy8(i) && checkIfThereIsAtLeast1OddDigit(i)) {
  9.                 System.out.println(i);
  10.             }
  11.         }
  12.     }
  13.     private static boolean checkIfTheSumOfDigitsIsDivisibleBy8 (int num){
  14.         String numInString = String.valueOf(num);
  15.         int sum = 0;
  16.         for (int i = 0; i < numInString.length(); i++) {
  17.             sum += Character.getNumericValue(numInString.charAt(i));
  18.         }
  19.         return sum%8==0;
  20.     }
  21.     private static  boolean checkIfThereIsAtLeast1OddDigit(int num){
  22.         String numInString = String.valueOf(num);
  23.         for (int i = 0; i < numInString.length(); i++) {
  24.             if (!(Character.getNumericValue(numInString.charAt(i)) % 2 == 0)) {
  25.                 return true;
  26.             }
  27.         }
  28.         return false;
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top