Hello, I have to write a program where I need to take an input from the user, a phrase with words seperated by spaces, and then print the phrase and show how many times a word is used in the phrase. I'm a beginner, I would like to know how everything works, so what I'm trying to do is at least understand how to take user input and manipulate in my program, so for now I just want to take input and print it. Here is my code:
import java.util.Scanner;
import java.lang.String;
import java.util.ArrayList;
public class wordlist
{
public static void main(String[] args)
{
int USER_MAX = 50;
System.out.print("Enter a phrase seperated by spaces: ");
Scanner input = new Scanner(System.in);
System.out.print('\n');
String[] phrase = new String[USER_MAX];
while (input.hasNextInt())
{
for(int i = 0; i < phrase.length; i++)
{
phrase[i] = input.next();
}
}
for(int i = 0; i < phrase.length; i++)
{
System.out.print(Arrays.toString(phrase));
}
}
}
When I compile, I get this error message:
C:\Users\Desktop\wordlist.java:31: error: cannot find symbol
System.out.print(Arrays.toString(phrase));
^
symbol: variable Arrays
location: class wordlist
1 error
[Finished in 0.7s with exit code 1]
I don't know why. Is it because i have to use an Array List? I tried that and I don't know how it works. Thanks in advance for the help.