I'm a beginner in Java and practicing to code by myself. I'm using a book to teach me how to code and I'm stuck on a project where it includes creating a String array and determining its length. Here's my sample work. It's a simple baby name suggestion program.
public class BabyName {
public static void main(String[] args) {
String[] nameListOne = {"Alvin", "Elmer", "Angel", "Michael", "Tim", "Jude", "Gabriel", "Raphael", "John", "Smith", "Carl", "Mike"};
String[] nameListTwo = {"", "Mark", "Posh", "Jake", "Cloud", "Star", "Ben", "Sam", "Kim", "Mark", "Simeon", "Louie", "Nat", "Matt", ""};
int nameOneLength = nameListOne.Length;
int nameTwoLength = nameListTwo.Length;
int rand1 = (int) (Math.random() * nameOneLength);
int rand2 = (int) (Math.random() * nameTwoLength);
String babyname = nameListOne[rand1] + " " + nameListTwo[rand2];
System.out.println("Your suggested baby name is " + babyname);
}
}
I then get this errors when I tried to compile it:
BabyName.java:6: error: cannot find symbol
int nameOneLength = nameListOne.Length;
^
symbol: variable Length
location: variable nameListOne of type String[]
BabyName.java:7: error: cannot find symbol
int nameTwoLength = nameListTwo.Length;
^
symbol: variable Length
location: variable nameListTwo of type String[]
2 errors
I don't know what I did wrong here. I only followed what's written on the book.
Hope someone can help.
length, notLength.