fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. { // write code to find number in array and return index of array, if not found print -1
  12.  
  13. int[] arr = {1, 2, 3, 4};
  14.  
  15. int target = 3;
  16.  
  17. int value = 0;
  18.  
  19. for (int i = 0; i < arr.length; i++) {
  20. if (arr[i] == target) {
  21. value = i;
  22. System.out.println(value);
  23. //return value;
  24.  
  25. }
  26. }
  27.  
  28. value = -1;
  29. System.out.println(value);
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //publci static void printTarget(int[] x; int target y){}
  39.  
  40. }
  41. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
2
-1