Input 2 numbers and find their sum in Java
Input - Question 1
In this question, we will see how to input two numbers in Java programming using the java input and find their sum. To know more about java input click on the java input lesson.
Q1) Write a program in Java to input two numbers and find their sum.
Program
import java.util.Scanner;
public class Q1
{
public static void main(String args[])
{
int a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 numbers");
a=sc.nextInt();
b=sc.nextInt();
c=a+b;
System.out.print("Sum=" + c);
}
}
Output
Enter 2 numbers 15 26 Sum=41