0

What's wrong in my code

9th Dec 2022, 6:47 AM
Vinze Raymundo
Vinze Raymundo - avatar
4 Answers
+ 5
Vinze Raymundo Your code should be like this: import java.util.Scanner; public class Program { //your code goes here /* User message: "1", Reply: "Order confirmed" User message: "2", Reply: "[email protected]" For any other number, the reply should be: "Try again". */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int number = sc.nextInt(); switch(number){ case 1: System.out.println("Order confirmed"); break; case 2: System.out.println("[email protected]"); break; default: System.out.println("Try again"); } } } Therefore, you misspelt the word 'nextInt()' and there were some syntax error for enclosing braces.. And after removing that bot method, now it's okay ... Hope you got your answer...
9th Dec 2022, 7:13 AM
Pixel
Pixel - avatar
+ 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 "[email protected]" when the user enters "1". here is a correct version https://code.sololearn.com/cxOF5WBAPO39/?ref=app
9th Dec 2022, 11:00 AM
Sadaam Linux
Sadaam Linux - avatar
+ 1
import java.util.Scanner; public class Program { //your code goes here /* User message: "1", Reply: "Order confirmed" User message: "2", Reply: "[email protected]" 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("[email protected]"); break; default: System.out.println("Try again"); } } }
9th Dec 2022, 6:47 AM
Vinze Raymundo
Vinze Raymundo - avatar
+ 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.
9th Dec 2022, 7:37 AM
Jayakrishna 🇮🇳