issue with linechanging in java

I am trying to write a code about an exercise reading a text and converting it to Morse code.
at printing i want it to show every word at a unique line but it seems like it doesnt recognises ” ” as a character. Here is the code:

import acm.program.*;
public class Morse extends Program{
public void run(){
    println("Hello, please enter the text that you want to convert to Morse.");
    String txt = readLine();
    txt = txt.toUpperCase();
    for(int j = 0;j <= txt.length()-1;j++){
        int i;
        for (i=0;i<=25;i++){
            if (alphabet[i]==txt.charAt(j)){
                if (txt.charAt(j)==' '){
                    System.out.print(System.lineSeparator());
                }else{
                    System.out.print(" " + code[i] + " ");
                }
            }
        }
    }
}
private final String[] code = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.","--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-","-.--", "--..","n"};
private final char[] alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' '};
}