# java一個除錯問題...

//==================== RandInt3.java ======================

import javax.swing.JOptionPane;

import java.io.*;

class RandInt3

{

static int[] setupArray(int n)

{

int a[] = new int[n];

for (int i=0; i<a.length; i++)

a[i] = (int)(Math.random()*6+1);

return a;

}

static String showArray(int[] a)

{

String s = "建立" + a.length + "個隨機數如下：";

for (int i=0; i<a.length; i++)

{

if (i%5==0)

s = s + "\n" + a[i]+ " ";

else

s = s + a[i] + " ";

}

s = s + "\n";

return s;

}

static String showcount(int[] a)

{

String s= "隨機數\t次數\n------\t----\n";

int count[] = {0, 0, 0, 0, 0, 0, 0,};

for (int i=0; i<a.length; i++)

count[a[i]]++;

for (int i=1; i<count.length; i++)

s=s+i+" "+count[i]+"\n";

return s;

}

static String score2()

{

String y = "";

int n=100;

int forntal=0;

int reverse=0;

for(int i=1; i<=n; i++)

{

Score2=(int)(Math.random()*2);

if (Score2==1)

forntal=forntal+1;

else

reverse=reverse+1;

return y;

}

public static void main(String args[])

{

int a[] = setupArray(20);

JOptionPane.showMessageDialog(null,showArray(a));

JOptionPane.showMessageDialog(null,showcount(a));

JOptionPane.showMessageDialog(null,score2());

}

}

### 2 個解答

• 志明
Lv 5
1 0 年前
最佳解答

static String score2() {

String y = "";

int n = 100;

int forntal = 0;

int reverse = 0;

for (int i = 1; i <= n; i++) {

int Score2 = (int) (Math.random() * 2);//你忘了定義資料型別 int Score2

if (Score2 == 1)

forntal = forntal + 1;

else

reverse = reverse + 1;

}//這裡要有for迴圈的括弧

return y;//這裡y還沒做動作哦…所以回傳會沒意義哦!!

}

2008-08-27 09:19:20 補充：

static String score(int x) {

String z = null;

int n = 0;

String o = "";

for (int i = 1; i <= n; i++) {

if (n % i == 0) {

o += i + "|";

z = "n" + "的因數: " + o + "標題: 因數";

}

}

return z;

}

參考資料： myself
• 1 0 年前

static String score(int x)

{

int n;

String o="";

for(int i=1;i<=n;i++)

{

if(n%i == 0){

o+=i+"|";

z="n"+"的因數: "+o,"標題: 因數";

}

}

return z;

}

.

.

.

這一段看上去有什麼錯 0.0