Life, the Universe, and Everything else - JAVA

Why doesn’t this code work?

import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(true){
String str = s.nextLine();
if(str.equals(“49”))
break;
else
System.out.println(str);
}
}
}

@bsqrt : You should break on “42” not on “49” . Read the question again .

2 Likes

Also, you shouldn’t use Scanner. It’s very slow in taking input. Use InputStreamReader and BufferedReader. Your class name doesn’t need to be Main if it’s not public. This way you can have multiple codechef problem solutions organized in one folder.

Welcome to CodeChef and be patient in your endeavours, CodeChef problems can be frustrating sometimes. Check out the Editorials for that problem which you can’t solve.

Happy Hacking!

Plz format the question neatly …