-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLuckyNumber.java
31 lines (26 loc) · 1 KB
/
LuckyNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class LuckyNumber {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
int s1 = 0;
for(int i = 0; i<n; i++){
s1+=Integer.parseInt(String.valueOf(s.charAt(i)));
}
int s2 = 0;
for(int i = n; i<s.length(); i++){
s2+=Integer.parseInt(String.valueOf(s.charAt(i)));
}
if (s1 == s2){
System.out.println("LUCKY");
}
else{
System.out.println("UNLUCKY");
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}