Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pr10TopNumber_v2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < number ; i++) {
- if(checkForDivisible(i)&&checkForOdd(i)){
- System.out.println(i);
- }
- }
- }
- private static boolean checkForDivisible(int number) {
- boolean isDivisible = false;
- int sumDigits = 0;
- while (number > 0) {
- int digit = number % 10;
- sumDigits += digit;
- number /= 10;
- }
- if (sumDigits % 8 == 0) {
- isDivisible = true;
- }
- return isDivisible;
- }
- private static boolean checkForOdd(int number) {
- boolean isOdd = false;
- while (number > 0) {
- int digit = number % 10;
- if (digit % 2 != 0) {
- isOdd = true;
- break;
- }
- number /= 10;
- }
- return isOdd;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement