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