Computer Science, asked by akhilagarlapati, 1 month ago

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

Answered by shettyshitil
1

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:

Answered by SaurabhJacob
2

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.
Similar questions