-3

I want to be able to make my if statement restart the program if "Yes" is inputted, end the program if "No" is imputed, and say "Capitalization is important" if neither "Yes" or "No" is inputted.

Scanner sc = new Scanner(System.in);
    final String vowels = "aeiouAEIOU";
    System.out.println("Enter your word:");
    String word = sc.nextLine();
    while (!word.equalsIgnoreCase("done"))
    {
        String beforVowel = "";
        int cut = 0;
        while (cut < word.length() && !vowels.contains("" + word.charAt(cut)))
        {
            beforVowel += word.charAt(cut);
            cut++;
        }
        if (cut == 0)
        {
            cut = 1;
            word += word.charAt(0) + "w";
        }
        System.out.println(word.substring(cut) + beforVowel + "ay");

      Scanner keyboard = new Scanner (System.in);
      System.out.print("Do you wish to convert another setence ");
      String name = keyboard.nextLine();
      if(name = "Yes"){
          new Prog508a().launch;
      }
      if(name = "No"){
      break;
      }
      else{
      System.out.print("Capitalzation is important.");
      }
  • 2
    You're comparing well String values in `!word.equalsIgnoreCase("done")`, so why are you doing `if(name = "Yes"){`?(which is not a comparison BTW). – Alexis C. May 04 '14 at 13:48
  • 1
    This program should not even compile: (name = "Yes") is `String`, which is not compatible with boolean, which is expected inside `if`, please fix this expression with `if (name.equals("Yes")) {` – Dmitry Ginzburg May 04 '14 at 14:01

1 Answers1

0
String name = keyboard.nextLine();


if(name = "Yes"){
      new Prog508a().launch;
  }
  if(name = "No"){
  break;
  }

This is really not a good way to do this, I suggest you use method returns instead.

Also you should not use

if(name = "Yes")

Since it is not a comparison, a better way of doing this would be

if(name.contains("y") || name.contains("Y")){

As this allows the user to enter anything starting with y or Y, but if you really want to use 'Yes' then you should do

if(name.equals("Yes"))
TechAUmNu
  • 152
  • 1
  • 3
  • 11