fork(7) 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. {
  12. String s = "this is a long sentence";
  13. int i = s.indexOf('i'); // the first 'i' in String is at index 2
  14. int j = s.indexOf("long"); // the index of the first occurrence of "long" in s is 10
  15. int k = s.indexOf('z'); // k is -1 because 'z' was not found in String s
  16. int h = s.indexOf("LoNg"); // h is -1 because "LoNg" was not found in String s
  17.  
  18. System.out.println(i);
  19. System.out.println(j);
  20. System.out.println(k);
  21. System.out.println(h);
  22. }
  23. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
2
10
-1
-1