题目描述
彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。
输入格式
输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。
输出格式
对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.。
输入样例
在这里给出一组输入。例如:
2
233008
123456
输出样例
在这里给出相应的输出。例如:
You are lucky!
Wish you good luck.
package com.ty.java;
import java.util.Scanner;
public class Height {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N,x,a,b,c,d,e,f;
N = sc.nextInt();
for (int i = 0; i < N; i++) {
x = sc.nextInt();
a=x%10;
b=x/10%10;
c=x/100%10;
d=x/1000%10;
e=x/10000%10;
f=x/100000;
if (a + b + c == d + e + f){
System.out.println("You are lucky!\n");
}
else {
System.out.println("Wish you good luck.\n");
}
}
代码运行如下:
com.ty.java.Height
2
233008
You are lucky!
123456
Wish you good luck.
Process finished with exit code 0
}
}