Given two int values, return their sum. Unless the two values are the same, then return double their sum.
sumDouble(1, 2) → 3
sumDouble(3, 2) → 5
sumDouble(2, 2) → 8
Solution:
import java.util.Scanner;
class Test
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enetr First Number= ");
int a=sc.nextInt();
System.out.print("Enetr First Number= ");
int b=sc.nextInt();
if(a==b)
{
int c=2*(a+b);
System.out.println(c);
}
else
{
int d=a+b;
System.out.println(d);
}
}
}
sumDouble(1, 2) → 3
sumDouble(3, 2) → 5
sumDouble(2, 2) → 8
Solution:
import java.util.Scanner;
class Test
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enetr First Number= ");
int a=sc.nextInt();
System.out.print("Enetr First Number= ");
int b=sc.nextInt();
if(a==b)
{
int c=2*(a+b);
System.out.println(c);
}
else
{
int d=a+b;
System.out.println(d);
}
}
}
No comments:
Post a Comment