Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- boolean flag = false;
- do {
- Scanner console = new Scanner(System.in);
- System.out.print("Give number: ");
- int input = console.nextInt();
- int i = 0;
- Integer[] num_array = new Integer[5];
- //Βάζω τα ψηφία σε έναν πίνακα
- while (input > 0) {
- num_array[i++] = input % 10;
- input = input / 10;
- }
- //Πρέπει να κάνεις reverse την σειρά του πίνακα γιατί τα ψηφία είναι ανάποδα, εκτός αν θες να παίξεις με ανάποδο πίνακα no prob
- Collections.reverse(Arrays.asList(num_array));
- //Πρώτος κανόνας
- if (num_array[0] + num_array[1] == num_array[2]) {
- if ((num_array[0] % 2 == 0 && num_array[1] % 2 == 0) || //Έλεγχος αν είναι και οι δύο άρτιοι
- (num_array[0] % 2 != 0 && num_array[1] % 2 != 0)) { // Έλεγχος αν είναι και οι δυο περιττοί
- System.out.println("1st rule");
- //Δεύτερος κανόνας
- if (num_array[2] % 8 < 4) {
- System.out.println("2nd rule");
- //Τρίτος κανόνας
- int fusion = num_array[3] * 10 + num_array[4];
- if (fusion % 3 == 0 || fusion % 5 == 0) {
- System.out.println("3rd rule");
- flag = true;
- }
- }
- }
- }
- if (flag) {
- System.out.println("\n\nGood\n\n");
- } else {
- System.out.println("\n\nBad\n\n");
- }
- }while (!flag);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement