Advertisement
jwrbg

АСД

Mar 6th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1.                                         ТАКА НЕ ГО ХАРЕСВА
  2. package TechModule;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class p03_MethodsTopNumber {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int n = Integer.parseInt(scanner.nextLine());
  10.         for (int i = 0; i < n; i++) {
  11.             int number = i;
  12.             int result = 0;
  13.             int lastDigit = 0;
  14.             boolean isDigit=false;
  15.  
  16.             while (number != 0) {
  17.                 lastDigit = number % 10;
  18.  
  19.                 result += lastDigit;
  20.  
  21.                 number /= 10;
  22.  
  23.             }
  24.  
  25.             if (result % 8 == 0&& isOdd(lastDigit) ) {
  26.                 System.out.println(i);
  27.             }
  28.         }
  29.     }
  30.  
  31.     public static boolean isOdd(int digit) {
  32.  
  33.         return digit % 2 != 0;
  34.  
  35.     }
  36. }
  37. ----------------------------------------------------------------------------------------------------------------------------
  38.                                             ТАКА СТАВА
  39.  
  40. package TechModule;
  41.  
  42. import java.util.Scanner;
  43.  
  44. public class p03_MethodsTopNumber {
  45.     public static void main(String[] args) {
  46.         Scanner scanner = new Scanner(System.in);
  47.         int n = Integer.parseInt(scanner.nextLine());
  48.         for (int i = 0; i < n; i++) {
  49.             int number = i;
  50.             int result = 0;
  51.             int lastDigit = 0;
  52.             boolean isDigit=false;
  53.  
  54.             while (number != 0) {
  55.                 lastDigit = number % 10;
  56.  
  57.                 result += lastDigit;
  58.                 if (!(lastDigit % 2 == 0)){
  59.                     isDigit=true;}
  60.                 number /= 10;
  61.  
  62.             }
  63.  
  64.             if (result % 8 == 0&& isDigit ) {
  65.                 System.out.println(i);
  66.             }
  67.         }
  68.     }
  69.  
  70.  
  71.    
  72. }
  73. -------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement