Write a Program that accepts three integer values (a,b,c) and returns their sum. However, if one of the values is 13 then it does not count towards the sum and the next number also does not count. So for example, if b is 13, then both b and c do not count.
Include a class UserMainCode with a static method getLuckySum which accepts three integers. The return type is integer representing the sum.
Create a Class Main which would be used to accept the input integers and call the static method present in UserMainCode.
Input and Output Format:
Input consists of three integers.
Output consists of a single integer.
Refer sample output for formatting specifications.
Sample Input 1:
1
2
3
Sample Output 1:
6
Sample Input 2:
1
2
13
Sample Output 2:
3
Sample Input 3:
13
3
8
Sample Output 3:
8
Scanner sc=new
Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int sum=0;
if(a==13)
{
sum=c;
}
else
if(b==13)
{
sum=a;
}
else
if(c==13)
{
sum=a+b;
}
else
{
sum=a+b+c;
}
System.out.println(sum);
0 comments :
Post a Comment