Advertisement
jwrbg

asd

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