title: Whitespace Location Finding
body: <p>So the instructions I have are as follows:</p>
  
  <blockquote>
    <p>Write code to print the location of any space in the 2-character string passCode. Each space detected should print a separate statement followed by a newline. Sample output for the given program:
    Space at 1</p>
  </blockquote>
  
  <p>The code I currently have written is: </p>
  
  <pre><code>import java.util.Scanner;
  public class FindSpaces {
  public static void main (String [] args) {
    String passCode = "";
    passCode = "A ";
    if (Character.isWhitespace(passCode.charAt(0))){
       System.out.println("Space at " +passCode.indexOf(" "));
    }
    else if (Character.isWhitespace(passCode.charAt(1))){
       System.out.println("Space at " +passCode.indexOf(" ", 1));
    }
    else{
    }
  
    return;
      }
    }
  </code></pre>
  
  <p>Now this works sometimes but if I have more than one space in my input, it only ever prints one line. If it helps anyone, it is from zyBooks and I have no idea how to make it bring a second line showing a second whitespace.</p>