Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
strstr() function / indexOf() function
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { System.out.println(strStr("mississippi","issip")); } public static int strStr(String haystack, String needle) { if(needle.length()==0) return 0; for(int i=0;i<=haystack.length() - needle.length();i++){ for(int j = 0;j<needle.length()&&haystack.charAt(i+j)==needle.charAt(j);j++){ if(j==needle.length()-1) return i; } } return -1; } }
run
|
edit
|
history
|
help
0
Cola Machine
loding
swastik
Size and signedness of Java ints and longs
vechile
Crescente.java
JAVA # Karekök Hesaplama
overloading
Main.java
hw1p1