This question has already been answered:
- How to compare strings in java? 2 answers
Why doesn't the index of the found word appear on the console?
The user enters the word. The program searches the array and displays its index:
import java.util.Scanner; public class MassiveStrings { public static void main(String[] args) { Scanner scn = new Scanner(System.in); System.out.print("Введите слово: "); String object = scn.nextLine(); String[] word = { "Масло", "Вода", "Дерево", "Кефир", "Помидор", "Сельдерей", "Кувшин" }; for (int i = 0; i < word.length; i++) { if (word[i] == object) System.out.print("Ваш индекс" + i); } } }