title: How can I use IndexOf with Scanner?
body: <p>I'm a beginner in Java, so I apologize if this seems too easy for you to reply, still I hope I can get a little help from here. </p>
  
  <p>I wanted to get an input from the user with <code>Scanner</code>, writing a sentence. 
  Then the user would pick a word from that sentence. 
  And then with <code>string.indexof("")</code>, the program should count from which number the  word starts in that sentence. 
  But the result is always -1. And I don't understand why. </p>
  
  <pre><code>String a,b;
  
  Scanner sc= new Scanner(System.in);
  System.out.println("Please write a sentence");
  y=sc.next();
  
  Scanner sc2 = new Scanner(System.in);
  System.out.println("Please pick a word from that sentence");
  
  System.out.println("The word starts from=" + (y.indexOf(a=sc2.next())));
  </code></pre>