fork download
  1. import java.util.Scanner;
  2. class word_in_array
  3. {
  4. public static void main(String []args)
  5. {
  6. int n;
  7. Scanner s = new Scanner(System.in);
  8. String word;
  9.  
  10. System.out.println("Enter how many words to be entered");
  11. n = s.nextInt();
  12. System.out.println("Enter "+ n +" words");
  13. String words[]=new String[n];
  14. for(int i = 0; i<n;i++)
  15. {
  16. words[i] = s.next();
  17. }
  18.  
  19. System.out.println("Enter the word to be searched\n");
  20. word=s.next();
  21.  
  22. for (int i = 0; i<n;i++)
  23. {
  24. String a = words[i];
  25. if (a.equals(word))
  26. {
  27. System.out.println("This word is available.");
  28. }
  29. else
  30. {
  31. System.out.println("This is not available.");
  32. }
  33. }
  34. }
  35. }
Success #stdin #stdout 0.13s 37560KB
stdin
4
dog
cat
apple
man
man
stdout
Enter how many words to be entered
Enter 4 words
Enter the word to be searched

This is not available.
This is not available.
This is not available.
This word is available.