Problem: 2.18


 Question 2.18: Write a Java program to calculate the sum of two integers and return true if the sum is equal to a third integer.

Sample Output:

Input the first number : 5

Input the second number: 10

Input the third number : 15

The result is: true


Solution:

package com.company;
import java.util.Scanner;
public class Lab2problem18 {
    public static void main(String[] args)
    {
        Scanner Obj =new Scanner(System.in);
        System.out.println("enter the first value: ");
        int a =Obj.nextInt();
        System.out.println("enter the second value: ");
        int b =Obj.nextInt();
        System.out.println("enter the third value: ");
        int c =Obj.nextInt();

        int sum = a+b;
        if(sum == c)
        {
            System.out.println("true");
        }
        else{
            System.out.println("false");
        }
    }
}

Previous Post Next Post