0
What's wrong in my code
4 Answers
+ 4
1.The bot() method is declared inside the main() method, but it is not indented properly. As a result, the code will not compile.
2.The bot() method is missing the return type. It should be declared as public static void bot().
3.The nextlnt() method does not exist. The correct method to read an integer from the Scanner object is nextInt().
4.The switch statement is missing a break statement after the case 1 block. As a result, the code will always print "Order confirmed" and then "info@sololearn.com" when the user enters "1".
here is a correct version
https://code.sololearn.com/cxOF5WBAPO39/?ref=app
+ 1
import java.util.Scanner;
public class Program {
//your code goes here
/*
User message: "1", Reply: "Order confirmed"
User message: "2", Reply: "info@sololearn.com"
For any other number, the reply should be: "Try again".
*/
public static void main(String[] args) {
bot();
public static void bot (){
Scanner sc = new Scanner(System.in);
int number = sc.nextlnt();
switch(number){
case 1:
System.out.println("Order confirmed");
break;
case 2: System.out.println("info@sololearn.com");
break;
default:
System.out.println("Try again");
}
}
}
+ 1
Vinze Raymundo
If you want use bot() method in your code, add a closing brace after bot() call. It missing close brace.
public static void main(String[] args) {
bot();
} š
Also I already said, misspelled nextInt() ; capital i. //not nextlnt() , not l
With these 2 changes, your code works fine.