我知道它可能是世界上最无脑的答案,但是我不明白为什么在适当答案下的第一个if条件之后的其他声明不起作用,我只是想尽快上床而且我想要至少运行一次。
package PokerApp;
import java.util.Scanner;
public class PokerApp {
public static void main(String[] args) {
int card1 = 0;
int card2 = 0;
int play;
String fc1 = "", fc2 ="";
String answer = "";
Scanner scan = new Scanner(System.in);
System.out.println("Press 1 to evalaute your cards: ");
play = scan.nextInt();
while (play != 0){
System.out.println("First Card: ");
if (scan.hasNextInt())
{
card1 = scan.nextInt(9)+2;
}
else{
fc1 = scan.next();
switch(fc1)
{
case "A":
card1 = 14;
break;
case "K":
card1 = 13;
break;
case "Q":
card1 = 12;
break;
case "J":
card1 = 11;
break;
default:System.out.println("Incvalid entry");
}
}
System.out.println("Second card: ");
if (scan.hasNextInt())
{
card2 = scan.nextInt(9) +2;
}
else{
fc2 = scan.next();
switch (fc2)
{
case "A":
card2 = 14;
break;
case "K":
card2 = 13;
break;
case "Q":
card2 = 12;
break;
case "J":
card2 = 11;
break;
default:System.out.println("Invalid entry.");
}
}
System.out.println(card1 + "" + card2);
if(card1 == card2)
{
System.out.println("You have a pair.");
break;
}
//If no pair, suited engine runs conditions.
else{
System.out.println("Are your cards suited? (y/n): ");
answer = scan.next();
}
if (answer == "y");
{
if(card1 == card2++ || card1++ == card2);
{
System.out.println("Suited connectors.");
break;
}
else{
if(card1 >= 12 && card2 >=12)
{
System.out.println("High value suited cards.");
break;
}
else{
if(card1 >=12 || card2 >= 12)
{
System.out.println("In the making for a queen high flush, or better!");
break;
}
else
System.out.println("Fold");
break;
}
}
//If the cards are not suited.
}
}
}
}
答案 0 :(得分:0)
对比较字符使用单引号,对字符串使用双引号。同时删除If语句末尾的;
,因为通过添加;
,您创建的空语句不执行任何操作。
if (answer == 'y') // remove ;