implement a program to display the sum of two given numbers if the numbers are same. If the numbers are not same, display the double of the sum.
Answers
Answer:
package demo;
import java.util.Scanner;
public class selectionAssignment {
public static void main(String[] args) {
int num1, num2, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Number: ");
num1 = sc.nextInt();
System.out.println("Enter Second Number: ");
num2 = sc.nextInt();
sum = num1 + num2;
if(num1==num2) {
System.out.println("Sum of these numbers: "+sum);
}
else {
System.out.println("Sum of these numbers: "+(2*sum));
}
}
}
Explanation:
The python program for the given problem is,
a=int(input("Enter the first number = "))
b=int(input("Enter the second number = "))
if(a==b):
print("Sum is",a+b)
else:
print("Double Sum is",2*(a+b))
In the above program,
- 'a' and 'b' are the variables to store the numbers inputted by the user.
- Then the condition is used to check for the number is the same or not.
- After that, the sum is printed if the condition becomes true.
- And, double of the sum is printed when the given condition is not true.