public static void main (String args[])
{
int a[] = setupArray(100);
System.out.println(showArray(a));
/*下面代码小弟看不懂,很惭愧,请高手指导一下*/
// 計數器的數組,分別計數0-9
int count[]={ 0,0,0,0,0,0,0,0,0,0};
for(int i=0 ;i<a.length; i++)
// a[i]為0-9的數,因此,count[a[i]]++指a[i]對應的計數器增加一
count[a[i]]++;
System.out.println("随机数\t次数\n------\t----");
// 打印結果麼
for(int=0 ; i<count.length; i++ )
System.out.println(i+ "\t" +count[i]);
}
{
int a[] = setupArray(100);
System.out.println(showArray(a));
/*下面代码小弟看不懂,很惭愧,请高手指导一下*/
// 計數器的數組,分別計數0-9
int count[]={ 0,0,0,0,0,0,0,0,0,0};
for(int i=0 ;i<a.length; i++)
// a[i]為0-9的數,因此,count[a[i]]++指a[i]對應的計數器增加一
count[a[i]]++;
System.out.println("随机数\t次数\n------\t----");
// 打印結果麼
for(int=0 ; i<count.length; i++ )
System.out.println(i+ "\t" +count[i]);
}
for( int i=0; i<suit.length: i++)
{
while (true)
{
key=(int)(Integer.MAX_VALUE*Math.random())%sw.length;
if(sw[key]==false) break;
}
suit[i]=key;
sw[key]=true;
}
for (int i=0; i<suit.length; i++);
System.out.print();
}
//我想應該為
public class CardSuit {
public static void main(String args[]) {
int key, suit[] = new int[13];
boolean sw[] = new boolean[22];
for (int i = 0; i < suit.length ; i++) {
while (true) {
key = (int) (Integer.MAX_VALUE * Math.random()) % sw.length;
if (sw[key] == false)
break;
}
suit[i] = key;
sw[key] = true;
}
for (int i = 0; i < suit.length; i++)
System.out.println("" + suit[i]);
}
}
while (true) {
key = (int) (Integer.MAX_VALUE * Math.random()) % sw.length;
if (sw[key] == false)
break;
}
这里的第一个true从那里来的?
第一个true代表什么呢?
以后循环中的true是从那里来的呢?
当然,你写while(1)也是一样的
不过他说的while(1)应该是不行的!在JAVA中不支持这样!boolean 与int 不兼容!
可以这样写!
while(2==2){
}
呵呵!
{
static int[] setupArray(int n)
{
int a[] = new int[n];
for ( int i=0 ; i<a.length; i++)
a[i]=(int)(Math.random()*10);
return a;
}
static String showArray(int a[])
{
String s = "建立" +a.length + "个随机数如下:";
for(int i =0 ; i<a.length; i++)
{
if(i%10 == 0)
s=s + "\n" ;
else
s=s + a[i] + " " ;
}
s=s + "\n";
return s;
}
public static void main (String args[])
{
int a[] = setupArray(100);
System.out.println(showArray(a));
int count[]={ 0,0,0,0,0,0,0,0,0,0};
for(int i=0 ;i<a.length; i++)
count[a[i]]++;
System.out.println("随机数\t次数\n------\t----");
}
}为何报错,请教高手..!!!