Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1.  
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.         boolean flag = false;
  7.         do {
  8.             Scanner console = new Scanner(System.in);
  9.             System.out.print("Give number: ");
  10.             int input = console.nextInt();
  11.             int i = 0;
  12.  
  13.             Integer[] num_array = new Integer[5];
  14.  
  15.  
  16.             //Βάζω τα ψηφία σε έναν πίνακα
  17.             while (input > 0) {
  18.                 num_array[i++] = input % 10;
  19.                 input = input / 10;
  20.             }
  21.  
  22.             //Πρέπει να κάνεις reverse την σειρά του πίνακα γιατί τα ψηφία είναι ανάποδα, εκτός αν θες να παίξεις με ανάποδο πίνακα no prob
  23.             Collections.reverse(Arrays.asList(num_array));
  24.  
  25.             //Πρώτος κανόνας
  26.             if (num_array[0] + num_array[1] == num_array[2]) {
  27.                 if ((num_array[0] % 2 == 0 && num_array[1] % 2 == 0) || //Έλεγχος αν είναι και οι δύο άρτιοι
  28.                         (num_array[0] % 2 != 0 && num_array[1] % 2 != 0)) { // Έλεγχος αν είναι και οι δυο περιττοί
  29.                     System.out.println("1st rule");
  30.  
  31.                     //Δεύτερος κανόνας
  32.                     if (num_array[2] % 8 < 4) {
  33.                         System.out.println("2nd rule");
  34.  
  35.                         //Τρίτος κανόνας
  36.                         int fusion = num_array[3] * 10 + num_array[4];
  37.                         if (fusion % 3 == 0 || fusion % 5 == 0) {
  38.                             System.out.println("3rd rule");
  39.                             flag = true;
  40.                         }
  41.  
  42.                     }
  43.                 }
  44.  
  45.             }
  46.  
  47.             if (flag) {
  48.                 System.out.println("\n\nGood\n\n");
  49.             } else {
  50.                 System.out.println("\n\nBad\n\n");
  51.             }
  52.  
  53.         }while (!flag);
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement