我正在尝试读取用户输入“单身”“已婚”“合法分居”“寡妇/er”

ozxc1zmp  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(246)

这个问题在这里已经有了答案

java中的无效字符常量(1个答案)
上个月关门了。

/*

我正在尝试读取用户输入“单身”“已婚”“合法分居”“寡妇/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");
 } while (status == 'single' && status == 'married' && status == 'legally separated' && status =='widow/er');

返回readstatus;}

bvjveswy

bvjveswy1#

你提到了一个 String return type 在你的 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");
return;
    }
return status;
         } while (status == 'single' | status == 'married' | status == 'legally separated' | status =='widow/er');

相关问题