Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TechModule;
- import java.util.Scanner;
- public class p03_MethodsTopNumber {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- int number = i;
- int result = 0;
- int lastDigit = 0;
- while (number != 0) {
- lastDigit = number % 10;
- result += lastDigit;
- number /= 10;
- }
- if (result % 8 == 0&& isOdd(lastDigit)) {
- System.out.println(i);
- }
- }
- }
- public static boolean isOdd(int digit) {
- boolean isDigit = false;
- if (digit % 2 != 0){
- isDigit=true;}
- return isDigit;
- }
- }
- ----------------------------------------------------------------------------------------------------------
- A top number is an integer that holds the following properties:
- • Its sum of digits is divisible by 8, e.g. 8, 16, 88.
- • Holds at least one odd digit, e.g. 232, 707, 87578.
- Write a program to print all master numbers in the range [1…n].
- input
- 100 50
- output
- 17 17
- 35 35
- 53
- 71
- 79
- 97
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement