Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
Free Bestselling eBooks

It's easy: sign up in under 10 seconds, tell us what kind of eBooks you love & we'll email you a list of deals every day - FREE! Join now!
From our sponsors
JAVA編寫問題
Mar 18th 2014, 06:32

//兩人決鬥
public class TestDuel {

public static void main(String[] args)throws InterruptedException {
//宣告陣列並設初始值
boolean[] flags = {true,false};
int totalRound = 20;
int theRed = 0; //TheRed 累進步數
int theBule = 0; //TheBule

*** int[] tenRound = {true,false};

System.out.println("<< 雙方決鬥開始 >>");
while(theRed<totalRound && theBule<totalRound){
Thread.sleep(1000); //要處理 InterruptedExcetion(check exception)
theRed++; //代表紅方攻一回合
System.out.printf("紅方攻了%2d 回合...%n",theRed);

boolean isBuleStay = flags[((int)(Math.random()*10))%2];

**** boolean One hit kill =tenRound[((int)(Math.random()*(20-10+1)+10))];

if(isBuleStay){
System.out.println("藍方恍神 @ @ @ @ @ @");

**** }else if(One hit kill){
System.out.println("藍方失血過多死亡~~我竟然敗了~~");
break;
}
else{
theBule += 2; //代表藍方攻擊兩次
System.out.printf("藍方攻了%2d 回合....%n",theBule);
}
}//end of while
System.out.println("<<決鬥結束>>\n");
//三元條件運算子(比較條件 ? ture:false)
String win = theRed > theBule ?"菜鳥":"高手";
System.out.println(win+"=>獲得勝利了...");
}
}//end of Dule

帶*號的就是我要問的問題
我想寫一個可以在10回合後對手有可能會被一擊必殺,但是用if寫一直提示要boolean型別才能,不知道該怎麼寫
有誰可以幫幫我

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜

    iphone5s何時上市 發表在 痞客邦 留言(0) 人氣()