Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Pr10TopNumber {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int n = Integer.parseInt(reader.readLine());
- String numStr = "";
- for (int i = 1; i <= n; i++) {
- numStr = i + "";
- isTopNumber(numStr);
- }
- }
- private static void isTopNumber(String numStr) {
- boolean isDivideBy8 = false;
- boolean isOdd = false;
- int sumDigits = 0;
- for (int i = 0; i < numStr.length(); i++) {
- int digit = numStr.charAt(i) - '0';
- //by8
- sumDigits += digit;
- if (sumDigits % 8 == 0) {
- isDivideBy8 = true;
- }
- //lessOneOddDigit
- if (digit % 2 != 0) {
- isOdd = true;
- }
- //result
- if (isDivideBy8 && isOdd) {
- System.out.println(numStr);
- }
- isDivideBy8 = false;
- isOdd = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement