-2
 /*

I am trying to read user input "single" "married" "legally separated" "widow/er" only. */

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');

return readStatus;}

  • Would you please indent your code properly so we can read it without too much strain? Your IDE can do it for you — and for us. Thank you. – Ole V.V. Nov 19 '20 at 04:12
  • [I downvoted because if we cannot read your code, we cannot help you.](http://idownvotedbecau.se/unreadablecode/). – Ole V.V. Nov 19 '20 at 16:50

1 Answers1

0

You have mentioned a String return type in your readStatus() function,but you didn't put return statement.I think this would work fine.

        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');