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 ❓
3 Respuestas
+ 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`.
+ 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
}
}
0
Can you tell me by making program it's not working ??