Topic: 求助,一道java题为什么出现这样? |
Print this page |
1.求助,一道java题为什么出现这样? | Copy to clipboard |
Posted by: haha551 Posted on: 2007-09-08 02:14 import java.lang.Math; import java.util.Scanner; class AarrayReverse { public static void main(String args[]) { int a[]=new int[20]; for(int i=0;i<=15;i++) { Scanner sca=new Scanner(System.in); System.out.println("请输数组元素a["+"]"); a[i]=sca.nextInt(); } for(int i=0;i<=100;i++) { int middle=(int)(a.length/2*Math.random()); int radius=(int)(middle*Math.random()); int t; t=a[middle-radius+1]; a[middle-radius+1]=a[middle+radius+3]; a[middle+radius+3]=t; } for(int i=0;i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } 运行之后出现的请输入数组元素,但是在 输入数组元素之后怎么 会出现这样的 情况呢 ?如图:为什么呢 ? |
2.Re:求助,一道java题为什么出现这样? [Re: haha551] | Copy to clipboard |
Posted by: hubmygirl Posted on: 2007-09-09 18:15 import java.lang.Math; import java.util.Scanner; class AarrayReverse { public static void main(String args[]) { int a[] = new int[5]; Scanner sca = new Scanner(System.in); for (int i = 0; i < 5; i++) { System.out.println("请输数组元素a[" + "]"); a[i] = sca.nextInt(); } sca.close(); for (int i = 0; i <= 100; i++) { int middle = (int) (a.length / 2 * Math.random()); int radius = (int) (middle * Math.random()); int t; t = a[middle - radius + 1]; a[middle - radius + 1] = a[middle + radius + 3]; a[middle + radius + 3] = t; } for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } } //这个是因为你用的是,隔开,因此,有这样的错误,这个是运行异常,因此,你编译是没有问题的! |
3.Re:求助,一道java题为什么出现这样? [Re: haha551] | Copy to clipboard |
Posted by: hubmygirl Posted on: 2007-09-09 18:18 他Scanner sca = new Scanner(System.in);默认的是用空格隔开de,要不,你就要指明token! |
4.Re:求助,一道java题为什么出现这样? [Re: haha551] | Copy to clipboard |
Posted by: haha551 Posted on: 2007-09-10 23:59 谢谢你的帮助,我现在已经明白了。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |