Advertisement
jwrbg

asd

Mar 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package TechModule;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p03_MethodsTopNumber {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine());
  9.         for (int i = 0; i < n; i++) {
  10.             int number = i;
  11.             int result = 0;
  12.             int lastDigit = 0;
  13.  
  14.             while (number != 0) {
  15.                 lastDigit = number % 10;
  16.  
  17.                 result += lastDigit;
  18.                 number /= 10;
  19.  
  20.             }
  21.            
  22.             if (result % 8 == 0&&  isOdd(lastDigit)) {
  23.                 System.out.println(i);
  24.             }
  25.         }
  26.     }
  27.  
  28.     public static boolean isOdd(int digit) {
  29.         boolean isDigit = false;
  30.         if (digit % 2 != 0){
  31.             isDigit=true;}
  32.         return isDigit;
  33.     }
  34. }
  35. ----------------------------------------------------------------------------------------------------------
  36.  
  37.  
  38. A top number is an integer that holds the following properties:
  39. • Its sum of digits is divisible by 8, e.g. 8, 16, 88.
  40. • Holds at least one odd digit, e.g. 232, 707, 87578.
  41. Write a program to print all master numbers in the range [1…n].
  42. input
  43. 100           50
  44. output
  45. 17            17
  46. 35            35
  47. 53
  48. 71
  49. 79
  50. 97
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement