Java Questions :getLuckySum

$ads={1}

Java Questions :getLuckySum

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.

$ads={1}

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


$ads={1}

Sample Input 2:
1
2
13

Sample Output 2:
3


Sample Input 3:
13
3
8

Sample Output 3:
8


$ads={1}

import java.io.*;
import java.util.*;

public class Main {

public static void main(String[] args) {
    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);
}
}

 

$ads={1}

Post a Comment

Post a Comment (0)

Previous Post Next Post