user3372138
user3372138

Reputation: 1

cmd keeps telling me error cannot find symbol

I've been trying now for a couple days to run this but it hasn't gone through for some reason. This is the code:strong text

public class namegenerator {
    public static void main(string[] args) {

    string[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"};

    string[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"};

    int onelength = firstnames.length;
    int twolength = lastnames.length;

    int rand1 = (int) (Math.random() * onelength);
    int rand2 = (int) (Math.random() * twolength);

    String phrase = firstname [rand1] + " " + lastname [rand2];

    System.out.println("Your fake name is, " + phrase);

    }

}

Upvotes: 0

Views: 45

Answers (2)

libik
libik

Reputation: 23029

You had two mistakes.

String is with "S", not "s"

And in your String phrase= you did not add "s" to "firstname"

public static void main(String[] args) {

    String[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"};

    String[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"};

    int onelength = firstnames.length;
    int twolength = lastnames.length;

    int rand1 = (int) (Math.random() * onelength);
    int rand2 = (int) (Math.random() * twolength);

    String phrase = firstnames[rand1] + " " + lastnames[rand2];

    System.out.println("Your fake name is, " + phrase);

}

Upvotes: 2

Kakarot
Kakarot

Reputation: 4252

there is a typo in your main method declaration, the class name is String and not string

 public static void main(String args[])

Upvotes: 0

Related Questions