0

class Program { void main(int a,int b) { int c; c=a+b; System.out.println("Final value ="+c);

Plz tell what is wrong in this question ❓

1st Jun 2022, 4:04 AM
Shashank
Shashank - avatar
3 odpowiedzi
+ 2
1- At main() you should better declare a & b as c is declared and let it as is by default. 2- There are two } that aren't where they should. 3- If you want to add two numbers from user input, just declare a & b and assign to them values based on user input. 4- Also main() method should be always public and static so add `public` & `static` before `void`.
1st Jun 2022, 4:57 AM
Ervis Meta
Ervis Meta - avatar
+ 1
// done for the input utility import java.util.Scanner; class Program{ // the main() method should always be declared like this public static void main(String args[]){ // declaring variables int a,b,c; // declaring scanner Scanner sc = new Scanner(System.in); // retrieving input using .nextInt() System.out.print("Enter the 1-st number: "); a = sc.nextInt(); System.out.print("Enter the 2-nd number: "); b = sc.nextInt(); // adding them up c = a+b; // just printing them System.out.println(String.format("The sum is : %d",c)); // and the last two `}` that are in need to close the method and class } }
4th Jun 2022, 10:15 AM
Ervis Meta
Ervis Meta - avatar
0
Can you tell me by making program it's not working ??
4th Jun 2022, 9:46 AM
Shashank
Shashank - avatar