+ 1

What wrong in this Code ????

I am beginner in Java ( in programming too) , could any explain what's the idea of methods!!!! ... Check the code below : .... . ... 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();{ Scanner sc= new Scanner(System.in) ; int i =sc.nextInt() ; switch (i) { case 1 : System.out.println("Order confirmed"); break; case 2 : System .out.println ("info@sololearn.com"); break; default : System . out. println("Try again"); } } }

2nd Jan 2023, 6:10 PM
Mohammed Alawad Ballal
Mohammed Alawad Ballal - avatar
1 Resposta
+ 3
In line having : bot() ; { // here method bot() is not declares any where and it's invalid statements. Remove it. Even though if you declare it, you need to use it within main method. public static void main(String[] a) { //...here use statement.. } A method is a set of self contained instructions that result some operation on executing. example : public void display() { System.out.println("hello") ; } this is a method named display which prints "hello" on calling it. like display(); // outputs "hello"
2nd Jan 2023, 7:06 PM
Jayakrishna 🇮🇳