0

Does this code is right or need to do some changes? It basicly search the Given word by user in a String nd prnt index of word

{ Scanner input = new Scanner(System.in); String Sent="Anything is bttr xyz than nothing"; Serch(Sent,"xyz"); } public static void Serch(String sent,String word){ String n ; for (int i =0;i<sent.length();i++){ if (sent.charAt(i)!=' '){ n = sent.charAt(i)+""+sent.charAt(i+1)+""+sent.charAt(i+2); if ("xyz".equals(n)) { System.out.println("Index : "+i+" word is : "+n); n = n.replace(n," "); System.out.println(n); break; } } } }

15th Nov 2019, 11:31 AM
Abdul Wahab
Abdul Wahab - avatar
5 Respostas
+ 2
Where is your main method first of all?
15th Nov 2019, 11:33 AM
Avinesh
Avinesh - avatar
+ 1
Abdul Wahab you don't need to post entire code in description. If it doesn't fit due to character limit , use playground, and attach link in description. https://www.sololearn.com/post/75089/?ref=app
15th Nov 2019, 11:48 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Avinesh i just copy the Main method body i just code only because there is word limit in Description which is 128 maximum words thts why i have to remove the main method header
15th Nov 2019, 11:39 AM
Abdul Wahab
Abdul Wahab - avatar
0
Abdul Wahab the program outputs the result perfectly, what do you want now?
15th Nov 2019, 11:46 AM
Avinesh
Avinesh - avatar
0
Avinesh thanks. I didn't knew about this. Cux i am new one here sorry
15th Nov 2019, 11:50 AM
Abdul Wahab
Abdul Wahab - avatar