Java 我正在尝试读取用户输入“;“单一”&引用;“已婚”&引用;“合法分居”&引用;寡妇/er";只有
我正在尝试读取用户输入“单身”“已婚”“合法分居”“寡妇/er”。 */Java 我正在尝试读取用户输入“;“单一”&引用;“已婚”&引用;“合法分居”&引用;寡妇/er";只有,java,Java,我正在尝试读取用户输入“单身”“已婚”“合法分居”“寡妇/er”。 */ 返回readStatus;} 您在readStatus()函数中提到了字符串返回类型,但您没有放入return语句。我认为这样可以 public static String readStatus() { Scanner scan = new Scanner(System.in); String status = ""; do { System.out.print("Enter the
返回readStatus;} 您在
readStatus()
函数中提到了字符串返回类型
,但您没有放入return语句。我认为这样可以
public static String readStatus() {
Scanner scan = new Scanner(System.in);
String status = "";
do {
System.out.print("Enter the status of the taxpayer: ");
status = scan.nextLine();
if (status != 'single' && status != 'married' && status != 'legally separated' && status !='widow/er');
System.out.println("You have to type single. married, legally separated or widow/er");
} while (status == 'single' && status == 'married' && status == 'legally separated' && status =='widow/er');
但是问题是它一直显示“无效字符常量”你好,你能不能也给我们看一下错误消息。你能不能正确缩进你的代码,这样我们就可以不费力地阅读它?您的IDE可以为您和我们做到这一点。非常感谢。
public static String readStatus() {
Scanner scan = new Scanner(System.in);
String status = "";
do {
System.out.print("Enter the status of the taxpayer: ");
status = scan.nextLine();
if (status != 'single' && status != 'married' && status != 'legally separated' && status !='widow/er');
System.out.println("You have to type single. married, legally separated or widow/er");
} while (status == 'single' && status == 'married' && status == 'legally separated' && status =='widow/er');
public static String readStatus() {
Scanner scan = new Scanner(System.in);
String status = "";
do {
System.out.print("Enter the status of the taxpayer: ");
status = scan.nextLine();
if (status != 'single' | status != 'married' | status != 'legally separated' | status !='widow/er'){
System.out.println("You have to type single. married, legally separated or widow/er");
return;
}
return status;
} while (status == 'single' | status == 'married' | status == 'legally separated' | status =='widow/er');