Accept any two numbers, if the first number is greater than second number print the sum of these two numbers, otherwise print the value of subtraction of these two numbers. Write this program with the user of ternary operator.
Answers
Answered by
1
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers:");
int a = sc.nextInt();
int b = sc.nextInt();
int var = (a > b) ? (a+b) : (a-b);
System.out.println(var);
}
}
Explanation:
Similar questions