fork download
  1. import java.lang.*;
  2. import java.util.*;
  3.  
  4. class TestIndexOf {
  5. String[] arr;
  6. TestIndexOf(String[] arr) {
  7. this.arr = arr;
  8. }
  9.  
  10. public int indexOf(String s) {
  11. for(int i = 0; i <= arr.length-1; i++) {
  12. if(arr[i].equals(s)) {
  13. return i;
  14. }
  15. }
  16. return -1;
  17. }
  18.  
  19. public static void main(String[] args) {
  20. String[] arr = new String[20];
  21. for(int i = 0; i < arr.length; i++) {
  22. arr[i] = "str" + i;
  23. }
  24. TestIndexOf test = new TestIndexOf(arr);
  25.  
  26. Scanner in = new Scanner(System.in);
  27. while(in.hasNextLine()) {
  28. String next = in.nextLine();
  29. System.out.println(next + ": " + test.indexOf(next));
  30. }
  31. }
  32. }
Success #stdin #stdout 0.09s 380672KB
stdin
str0
str19
not found
stdout
str0: 0
str19: 19
not found: -1