# 如何才能让数组实现连续的输入和输出

``public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.println("请输入数字个数"); int n = sc.nextInt(); System.out.println("请输入数字"); Scanner ww = new Scanner(System.in); String[] a = new String[n]; for (int i = 1; i <= n; i++) { a[i] = ww.next(); } ttt(); } public static void ttt(int man) { for (int i = 0; i <= man; i++) { if (man == Math.pow(i, 2)) { System.out.println("对"); break; } if(man == i){ System.out.println("错"); } } } }``

1 条回答

• 我说我不帅他们就打我，还说我虚伪

解释见注释

``````public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("请输入数字个数");
int n = sc.nextInt();
System.out.println("请输入数字");
Scanner ww = new Scanner(System.in);
String[] a = new String[n];
for (int i = 0; i < n; i++)//定义数组长度为n,则i从0到n-1；不然数组不够放
{
a[i] = ww.next();
}
//ttt();  //这个函数要传递数值，如ttt(5);
}
public static void ttt(int man) {

for (int i = 0; i <= man; i++)//这里可以判断i<=Math.sqrt(man);减小运算量
{
if (man == Math.pow(i, 2))
{
System.out.println("对");
break;
}
if(man == i){
System.out.println("错");
}
}
}   ``````
2019-07-17 19:28:55
赞同 展开评论 打赏

578
1
0
532
1
0
554
1
0
477
1
0
2514
1
0
917
1
0
2088
2
0
2305
1
0
575
0
0
404
0
0