- 2
help code jave
Write a java program to display the sum of 2 numbers a and b if a>b and their product if a<=b.
3 odpowiedzi
+ 1
It will be better if you scanner input
+ 1
Show your attempt first
0
public static void main(String[] args)
{
int a;
int b;
int sum;
System.out.print("Enter two numbers to add\n");
String tempVar = ConsoleInput.scanfRead();
if (tempVar != null)
{
a = Integer.parseInt(tempVar);
}
String tempVar2 = ConsoleInput.scanfRead();
if (tempVar2 != null)
{
b = Integer.parseInt(tempVar2);
}
sum = a + b;
System.out.printf("Sum of the numbers = %d\n", sum);
}