小白求救,运行错误,但找不出问题在哪
在本地成功运行,也测试了好多组数据。但是本人可能欠缺经验,编写程序习惯不好,可能一些细节没注意,导致提交到OJ上去,显示运行错误。我自己又找不到问题。。。跪求大佬帮忙看看
####题目描述
在n个整数中查找指定数字。
####输入
输入数据有多组,每组数据包括两行,第一行包含一个整数n(0<n<=100)和n个整数。第二行包含一个整数m表示要查找的关键字。
####输出
如果在n个整数中有和m相等的输出该整数,如果没有输出null。
####样例输入
5 1 2 3 4 5
3
3 10 20 30
100
样例输出
3
null
小白的代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] array = new int[100];
while (true) {
int cin = sc.nextInt();
for (int i = 0; i < cin; i++) {
int inp = sc.nextInt();
array[i] = inp;
}
int inpp = sc.nextInt();
for (int i = 0; i < cin; i++) {
if (array[i] == inpp) {
System.out.println(inpp);
break;
}
else if (arr[i] != inpp && arr[i] == arr[cin - 1])
System.out.println("null");
}
}
}
}
#2019-10-26
问题已解决
while循环的循环条件不能用true,要用hasNext