[英]guessing game for java with a specific set of rules using a do-while loop
有人可以幫我弄清楚如何編寫以下游戲的代碼:
猜謎游戲
今天我們正在創建一個猜謎游戲。 以下是規則:
計算機隨機生成一個從 1 到 100 的數字。用戶自動獲得 2.00 美元用於支付他們的猜測。 用戶猜測並輸入一個數字。 計算機告訴人類三個標准之一猜測是正確的。 估計應該更高。 估計應該更低。 這是對原始程序的扭曲。 用戶應該繼續猜測,直到用戶猜出隨機數並且每次猜測花費 0.25 美元
需求標准:決策制定、用戶輸入、do-while循環
進口隨機 class
import java.util.Random;
將錢聲明為浮動。
聲明輸入掃描器。
聲明隨機數(100)。
int guess = new Random().nextInt(100);
/*
while money>0{
print out prompt to ask for input
take scanner input
if input is the random number{
print that you've won and end the loop or the program entirely:
break; or
System.exit(0);
}
else{
money-=.25;
if guess > random number
print that guess is greater
else
print that guess is less
}
}
*/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.