title: How to use a for loop inside a return method?
body: <p>For this program, I am struggling to create a for loop inside the return method ("notString"). I am trying to get the program to ask for a name six times; however, I get an error which tells me to add a return value, which is inside the for loop. </p>
  
  <p>This is the statement from which I have to create a program: Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged.    </p>
  
  <pre><code>import java.util.*;
   public class practice1 {
   public static void main(String[] args) {
      Scanner sc=new Scanner(System.in);
      String answer= notString(sc);
      System.out.println(answer);
  
  }
  public static String notString(Scanner sc){
      for(int i=0; i&lt;=6;i++){
        System.out.println("Input Name: ");
        String name= sc.nextLine();
        if(name.startsWith("not")){
            return name;
        }else 
            return "not"+name ;
        }
      }
  
  }
  </code></pre>