我在我的Intro Java编程课程中处于领先地位,并且想知道在if
语句中是否有快捷方式。将字符串转换为“if”语句中的int
基本上,我的程序收到扑克牌两个字符缩写,并返回全卡的名称
现在我的问题是(即“QS”返回“黑桃皇后”): 当我为编号卡2-10编写if
声明,我是否需要为每个数字单独声明,还是可以将它们合并到一个if
声明中?
检查在我的代码表示是一个整数这里是我的代码片段,以澄清(显然不是Java注释。):
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the card notation: ");
String x = in.nextLine();
if (x.substring(0,1).equals("A")){
System.out.print("Ace");
}
else if(x.substring(0,1) IS AN INTEGER) <= 10)){ // question is about this line
System.out.print(x);
}
else{
System.out.println("Error.");
}
}
}
您是否将“ten of spades”输入为“10S”或“TS”? – Bohemian
应该是10S,它会在任何尝试转换为字符时抛出一个曲线球 – Shwheelz
因此,任何套装中的10个是_three_字符的缩写? –