Monty374

Search Name

Nov 29th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package seachname;
  2.  
  3. import java.util.*;
  4.  
  5. public class Seachname {
  6.  
  7. public static void main(String[] args) throws Exception {
  8. Scanner search = new Scanner(System.in);
  9. String[] array = new String[20];
  10.  
  11. System.out.println("Please enter 20 names to sort");
  12.  
  13. for (int i = 0; i < array.length; i++) {
  14. array[i] = search.nextLine();
  15. }
  16.  
  17. System.out.print("Enter a search term: ");
  18. String name = search.next();
  19.  
  20. int i;
  21.  
  22. boolean found = false;
  23.  
  24.  
  25. for (i = 0; i < array.length; i++) {
  26. if (array[i] == name) {
  27. found = true;
  28.  
  29. }
  30. }
  31.  
  32.  
  33. if (found = true){
  34. System.out.println("Your search term of " + name + " these search results");
  35. }
  36.  
  37. else {
  38. System.out.println("Your search term of " + name + " did not return any results");
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment