Hi Josee, Look at this code, you can copy pasted it works. I also add some notes.
public class Program
public static void main(String args)
//It is better start as easy as you can use and then make it more complex
//Use a simpel String mySentence = "This is a sentence";
String input = "This is a sentence";
int n = input.length();
//Scanner in = new Scanner(System.in);
//String input = in.next();
//int n = input.length();
int begin = 0;
int last = 0;
//String words = new String[l];
String words = new String;
int j = 0; //Try to use a name that means your intent not just j, something like, "wordPosition"
//The problem with array like this is that they dont expand dynamically so you will have to give a predefined size, which in this case, so you can chose 4 to match the sentence in this example.
for (int i = 0; i < n; i++)
if (input.charAt(i) == ' ')
last = i;
words[j] = input.substring(begin, last);
begin = i + 1;
//words[j] = input.substring(begin);
for (int i = 0; i < words.length; i++)
Note: There is another issue in your program in your if statement, you only add a word if you find a blank space. you need
to count for the last word in the sentence since most of the time you don't add a space at the end of a sentence, this will make your program miss to add the last word.
You can also use split from java in the future but for learning you are doing great.