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!!!"); } } }
3 Respostas
+ 1
thanks Anton
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.
- 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")