Write a program to add two integers and print their sum.
Print ONLY the sum without any other string. Also assume
that the numbers to be added are being entered via
command line while your program is getting executed (Eg.
Use scanf statement in c, cin in C++, or Scanner class in
Java)
After typing your program, press the "Compile" button, and
you will see the output of your program with system
provided inputs below your program typing area. Once your
code compiles successfully and no output is wrong, press the
"Submit" button.
Answers
Answered by
35
Step-by-step explanation:
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.print("Input the first number: ");
int num1 = input.nextInt();
System.out.print("Input the second number: ");
int num2 = input.nextInt();
int sum = num1 + num2;
System.out.println();
System.out.println("Sum: "+sum);
}
}
Copy
Sample Output:
Java code .
Mark my answer as brainliest mate ✍️✍️✍️✍️
Answered by
62
Answer: (in Java)
import java.util.*;
class Sum
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a + b);
}
}
Hope this helps!! Pls mark as brainliest!!
Similar questions