【Java】摸彩 → Random

後面一樣用布林Boolean下去做判斷,有嘗試用函式Function下去寫,不過失敗了!其random部分老師上課有讓我們抄原始碼sourse sode...阿翔就只把之前那猜拳的程式中間猜拳的部份換為random罷了!!
import java.io.*;
public class ex_random{
public static void main(String[]args) throws IOException{
boolean flag=true;
String str;
BufferedReader buf_YesNo;
buf_YesNo=new BufferedReader(new InputStreamReader(System.in));
System.out.println("摸彩摸彩..祝你中頭彩!");
do{
int i,intTransform;
double doubleAR;
System.out.println();
for(i=1;i<11;i++){
doubleAR = Math.random();
intTransform = (int)(doubleAR*100);
System.out.println("第\t"+i+"\t次為 "+intTransform);
}
System.out.println();

char charYesNo;
System.out.print("輸入Y繼續,N離開 → ");
str=buf_YesNo.readLine();
charYesNo=str.charAt(0);
if(charYesNo=='Y' || charYesNo=='y'){
System.out.println("====程式繼續====");
flag=true;
}else if(charYesNo=='N' || charYesNo=='n'){
System.out.println("====程式結束====");
flag=false;
}else{
System.out.println("====輸入錯誤====");
flag=false;
}
}while(flag);
System.out.println("");
}
}

留言

Popular Articles

MySQL 語法匯整