0

Can anyone tell me why is my code not working code in description

import java.io.*; public class Program { public static void main(String[] args) { InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); int m,i; Sysytem.out.println("Enter the number of Strings you want to enter "); m=Integer.parseInt(in.readLine()); String ss[]=new String[m]; for(i=0;i<m;i++); {Sysytem.out.println("Enter a word"); ss[i]=in.readLine(); } Sysytem.out.println("Enter the word you want to search"); search=in.readLine(); for(i=0;i<m;i++) { if(m[i].equalsIgnoreCase(search)) Sysytem.out.println("String found!!! "+search); else Sysytem.out.println("String not found!!!"); } } }

13th Oct 2018, 6:12 AM
Subhajit Dutta
Subhajit Dutta - avatar
3 Answers
+ 1
thanks Anton
14th Oct 2018, 3:52 AM
Subhajit Dutta
Subhajit Dutta - avatar
0
tipp: when you have problems with "{" and "}" you can intend blocks of codes that belong together Exemple: int x = 6; int y = 8; while(x != y){ if(x > y){ x -= y; }else{ y -= x; } } System.out.println("smallest divident:"); System.out.println(x); -> always when you make a "{" move the code below to the right a bit and when you close it ("}") you go back.
13th Oct 2018, 7:51 AM
Anton Böhler
Anton Böhler - avatar
- 1
import java.io.*; public class Program{ public static void main(String[] args) { InputStreamReader read = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); int m,i; System.out.println("Enter the number of Strings you want to enter "); m=Integer.parseInt(in.readLine()); String ss[]=new String[m]; for(i=0;i<m;i++){ System.out.println("Enter a word"); ss[i]=in.readLine(); } System.out.println("Enter the word you want to search"); String search=in.readLine(); for(i=0;i<m;i++){ if(ss[i].equalsIgnoreCase(search)){ System.out.println("String found!!! "+search); }else{ System.out.println("String not found!!!"); } } } } Thats as far as i can make it work but there is still 3 exeption handeling errors I couldn't fix. Good luck and happy Coding! Your bugs: -It's System.out.println(); -you made a ";" after an if clause -there were "{" and "}" missing -you wanted to get an element out of a int ("m"); it should have been an array (like "ss")
13th Oct 2018, 7:34 AM
Anton Böhler
Anton Böhler - avatar