偉倫 發問時間: 電腦與網際網路程式設計 · 1 0 年前

JAVA陣列輸出的問題

請問ㄧ下,要如何把輸出的6個値,分別丟到a,b,c,d,e,f,想了很久,還是不知道怎麼改,請各位大大指導一下~謝謝

import java.util.*;

public class boo {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);

int number[] = new int[49];

int random_nubmer;

int a,b,c,d,e,f;

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

random_nubmer = (int) (Math.random() * 49 + 1);

number[random_nubmer - 1] += 1;

}

for (int j = 1; j <= 49; j++) {

if (!(number[j-1] == 0)) {

System.out.println(j);

}

}

}

}

已更新項目:

請問ㄧ下,這個程式@@有辦法讓他按照順序排在決定abcdef嗎?

1 個解答

評分
  • 1 0 年前
    最佳解答

    Is this you want ? You must pay more time to study your Java skills

    import java.util.*;

    public class boo {

    public static void main(String args[]) {

    double a,b,c,d,e,f;

    a = (Math.random() * 49 + 1);

    System.out.println("a is = " + (int) a);

    b = (Math.random() * 49 + 1);

    System.out.println("a is = " + (int)b);

    c = (Math.random() * 49 + 1);

    System.out.println("a is = " +(int) c);

    d = (Math.random() * 49 + 1);

    System.out.println("a is = " +(int) d);

    e = (Math.random() * 49 + 1);

    System.out.println("a is = " + (int)e);

    f = (Math.random() * 49 + 1);

    System.out.println("a is = " + (int)f);

    }

    }

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。