public class BlackJackRules
{
Random generator = new Random();
int c = 0;
String card1;
/* Creates a random number which turns into
* a string card(card1).
*/
public String getCard()
{
c = generator.nextInt()+14;
if(c == 1)
card1 = "Ace";
else if(c == 2)
card1 = "Two";
else if(c == 3)
card1 = "Three";
else if(c == 4)
card1 = "Four";
else if(c == 5)
card1 = "Five";
else if(c == 6)
card1 = "Six";
else if(c == 7)
card1 = "Seven";
else if(c == 8)
card1 = "Eight";
else if(c == 9)
card1 = "Nine";
else if(c == 10)
card1 = "Ten";
else if(c == 11)
card1 = "Jack";
else if(c == 12)
card1 = "Queen";
else if(c == 13)
card1 = "King";
return card1;
}
}
,這裏是驅動程序....不明白爲什麼我的方法不工作?
public class BlackJack
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String userStart = new String();
String userQuit = new String();
String card1 = new String();
System.out.println("Would you like to play some BlackJack?");
userStart = scan.next();
if(userStart.equalsIgnoreCase("yes"))
{
System.out.println("Here we go...");
while(userQuit.equalsIgnoreCase("yes"))
{
System.out.println("Your first card is a " + card1.getCard());
}
}
else
System.out.println("Okay.");
}
}
}
我實在不明白它...我試圖重新安排我的代碼。我很高興參加高中的AP課程,並且正在爲方法概念而努力。謝謝你的幫助!
_isn't working_是什麼意思? –
請使用開關(c)'... – nhgrif
請提供某種「所需輸出」和「實際輸出」。它不是在編譯?它是否拋出異常?它只是給出意想不到的輸出? – merlin2011