-
-
Save mariiaKolokolova/3a9d272b0b07535e1a44d5195b05fef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package maricka.kolokolova; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Please, input your four-digit number to check is it lucky number or not:"); | |
int num; | |
int check; | |
num = sc.nextInt(); | |
check = num / 1000; | |
if (check < 1 || check > 9) { | |
System.out.println("Your number is not correct. Please input one more time."); | |
} else { | |
int n1; | |
int n2; | |
int n3; | |
int n4; | |
int sum1; | |
int sum2; | |
n1 = num / 1000; | |
n2 = num / 100 % 10; | |
n3 = num / 10 % 10; | |
n4 = num % 10; | |
sum1 = n1 + n2; | |
sum2 = n3 + n4; | |
if (sum1 / 10 > 0) { | |
sum1 = sum1 / 10 % 10 + sum1 % 10; | |
} | |
if (sum2 / 10 > 0) { | |
sum2 = sum2 / 10 % 10 + sum2 % 10; | |
} | |
if (sum1 == sum2) { | |
System.out.println("Your number is lucky!"); | |
} else { | |
System.out.println("Unfortunately, but your number is not lucky."); | |
} | |
} | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment