herrDeng網內搜尋

自訂搜尋

Ads

2016年6月14日 星期二

練習2

模擬兩顆骰子擲三次,並計算總點數

10 則留言:

B10433044吳玉瀚 提到...

import java.util.*;
public class S02 {
public static void main(String[] args) {
int[][] x=new int[2][3];
Random rdm=new Random();
int sum=0;
for(int n=0;n <=2;n++){
for(int i=0;i<=1;i++){
x[i][n]=rdm.nextInt(6)+1;
sum+=x[i][n];
System.out.print("["+x[i][n]+"]");
}
}
System.out.print(sum);
}
}
[1][2][4][2][4][4]17

李佳明B10433023 提到...

import java.util.Random;

public class EX2 {

public static void main(String[] args) { int [] data =new int[10] ; int i; Random ran = new Random (); for(i=0;i<10;i++) { data[i]= ran.nextInt(100)+1; System.out.print(data[i] +" "); } } }

李佳明B10433023 提到...

import java.util.Random;

public class A2 {

public static void main(String[] args) { int[] data=new int[6]; int i; int sum=0; Random ran= new Random(); for(i=0;i<6;i++) { data [i]=ran.nextInt(6)+1; System.out.print(data[i]+" "); sum=sum+data[i]; } System.out.print(sum); } }

B10433044吳玉瀚 提到...

import java.util.*;
public class S02 {
public static void main(String[] args) {
int[][] x=new int[3][2];
Random rdm=new Random();
int sum=0;
for(int n=0;n <=1;n++){
for(int i=0;i<=2;i++){
x[i][n]=rdm.nextInt(6)+1;
sum+=x[i][n];
System.out.print("["+x[i][n]+"],"+"["+x[i][n]+"]\n");
}
}System.out.print("總和:"+ sum);
}
}
[4],[4]
[1],[1]
[4],[4]
[6],[6]
[2],[2]
[2],[2]
總和:19

B10433042 提到...

import java.util.Random;

public class fcvcv {

public static void main(String[] args) { Random rnd=new Random(); int X[][]=new int[3][2]; int Sum=0; for(int i=0;i<3;i++){ X[i][0]=rnd.nextInt(6)+1; X[i][1]=rnd.nextInt(6)+1; System.out.println(X[i][0]+","+X[i][1]); Sum=Sum+X[i][0]+X[i][1]; } System.out.println("sum"+Sum); } }

b10433014 提到...

import java.util.Random;

public class xzcaq {

public static void main(String[] args) { Random rnd=new Random(); int X[][]=new int[3][2]; int sum=0; for(int i=0;i<3;i++){ X[i][0]=rnd.nextInt(6)+1; X[i][1]=rnd.nextInt(6)+1; System.out.println(X[i][0]+","+X[i][1]); sum=sum+X[i][0]+X[i][1]; } System.out.println("sum="+sum); } }

B10433034陳智揚 提到...

import java.util.*;
public class S02 {
public static void main(String[] args) {
int[][] x=new int[3][2];
Random rdm=new Random();
int sum=0;
for(int n=0;n <=1;n++){
for(int i=0;i<=2;i++){
x[i][n]=rdm.nextInt(6)+1;
sum+=x[i][n];
System.out.print("["+x[i][n]+"],"+"["+x[i][n]+"]\n");
}
}System.out.print("總和:"+ sum);
}
}
[4],[4]
[1],[1]
[4],[4]
[6],[6]
[2],[2]
[2],[2]
總和:19

B10433039游叡恩 提到...

import java.util.Random;

public class fcvcv {

public static void main(String[] args) { Random rnd=new Random(); int X[][]=new int[3][2]; int Sum=0; for(int i=0;i<3;i++){ X[i][0]=rnd.nextInt(6)+1; X[i][1]=rnd.nextInt(6)+1; System.out.println(X[i][0]+","+X[i][1]); Sum=Sum+X[i][0]+X[i][1]; } System.out.println("sum"+Sum); } }

B10433040葉峻宇 提到...

import java.util.Random;

public class abc123 {

public static void main(String[] args) { Random rnd=new Random(); int X[][]=new int[3][2]; int Sum=0; for(int i=0;i<3;i++){ X[i][0]=rnd.nextInt(6)+1; X[i][1]=rnd.nextInt(6)+1; System.out.println(X[i][0]+","+X[i][1]); Sum=Sum+X[i][0]+X[i][1]; } System.out.println("sum"+Sum); } }

B10133157 蔡翔杰 提到...

import java.util.Random;

public class abc123 {

public static void main(String[] args) { Random rnd=new Random(); int X[][]=new int[3][2]; int Sum=0; for(int i=0;i<3;i++){ X[i][0]=rnd.nextInt(6)+1; X[i][1]=rnd.nextInt(6)+1; System.out.println(X[i][0]+","+X[i][1]); Sum=Sum+X[i][0]+X[i][1]; } System.out.println("sum"+Sum); } }

Related Posts Plugin for WordPress, Blogger...

熱門文章