0

I am running a program test and Java kept on showing me this error message :

java: <identifier> expected

Can you please tell me what is wrong with my code?

package com.Benjamin;

public class Main {

    public static void main(String[] args) {
        String wordListOne = "24/7", "wine", "shoes", "cake", "car";
        String wordListTwo = "cat", "Islam", "boat", "lake", "puppy";
        String wordListThree = "ballon", "football", "joy", "pie", "war";
        int oneLength = wordListOne.length;
        int twoLength = wordListTwo.length;
        int threeLength = wordListThree.length;
        int rand1 = (int) (Math.random() * oneLength);
        int rand2 = (int) (Math.random() * twoLength);
        int rand3 = (int) (Math.random() * threeLength);
        String phrase = wordListOne [rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3] + "." ;
        System.out.println(phrase);
    }
}
Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • 1
    What do you expect this line to do? `String wordListOne = "24/7", "wine", "shoes", "cake", "car";` – tgdavies Feb 14 '21 at 11:42
  • 1
    [How to initialize an array in Java?](https://stackoverflow.com/questions/1938101/how-to-initialize-an-array-in-java) – luk2302 Feb 14 '21 at 11:44
  • Does this answer your question? [How to initialize an array in Java?](https://stackoverflow.com/questions/1938101/how-to-initialize-an-array-in-java) – zkoza Feb 14 '21 at 19:31

1 Answers1

0

String wordListOne = "24/7", "wine", "shoes", "cake", "car";

String wordListTwo = "cat", "Islam", "boat", "lake", "puppy";

String wordListThree = "ballon", "football", "joy", "pie", "war";

You're trying to assign multiple strings to a String variable, a String variable can only contain only one string, between quotes.

Perhaps you might wanna use an array of strings: check here

luk2302
  • 55,258
  • 23
  • 97
  • 137
mariuss
  • 1,177
  • 2
  • 14
  • 30