Good day to all! There was a problem with checking the array in the java programming language. Briefly: There is a variable for user input, there is an array, and there is an if branch, and yes .. There is a random object. The user enters the word: Hi (Must pass the if check) After checking the array, the function of displaying the message to the user is called (From the second array, this should be random);

  1. How to write an array? (And what would the code look like normally);
  2. How to make an array check in if? (I used equals (););
  3. How to display a random phrase from an array? (Specifying an array with a random variable does not work);

A piece of code (chopped):

String setscan = scans.nextLine();//Считывает ввод пользователя; setscan = setscan.replaceAll(" +", "");//Игнорирует пробелы при вводе; String[] dict_one = { "Добрый день", "Привет", "Здравствуй"}; Random rnd = new Random(); //Создаем новый объект класса Random; int rnds = rnd.nextInt(2); // Генерируем числа от 0 - 2; //Словарь 1, проверка - ответ; if (setscan.equals(dict_one)) { System.out.println(dict_one[rnds]); 

I will be very grateful! Notes: I'm new to the forum, just like in java;

    1 answer 1

     if (Arrays.asList(dict_one).contains(setscan)) System.out.println(dict_one[rnds]); 
    • Fine! Thank you, it works. - Sergey Richter