write a program by entering two numbers and find the sum
Answers
JAVA
Java is a machine independent language which can work on any platform.It is written within a class. The variable and functions are declared within a class.
Java is case sensitive language.
Package is the set of many classes.
The following programming us done by the io package of Java.
CODING
import Java. io. *;
class sum
{
public static void main(String args[])throws Exception
{
DataInputStream in= new DataInputStream(Syst em . in);
{
int a, b, s=0;
System . out . println("Enter any two nunbers");
a = Integer. parseInt(in . readLine());
b = Integer. parseInt(in . readLine());
s= a+ b;
Sy stem . out . println("The Sum is "+s);
}
}
Ou tput
a =15
b= 25
The sum is 40
Variable description
- int a = To store the value of first number inputed by the user.
- into b= To store the value of second number inputed by the user.
- int s =To store the sum of the two numbers inputed by the user
Question :-
Write a program by entering two numbers and find the sum.
Asked :-
A program to type the sum of two numbers.
Answer Starts :-
- Valuable Description
Data type Variables Descriptions
int n1 To except value of
first number.
int n2 To except value of
second number.
int sum To except value of
the sum of n1 and n2.
Program Starts
import java.util.Scanner;
public class AddTwoNumbers
{
public static void main(String args[ ]);
{
int n1, n2, sum;
Scanner sc = new scanner (System.in);
System.out.println("Enter first number:")
n1 = sc.nextInt( );
System.out.println("Enter second number:");
n2 = sc.nextInt( );
sum = n1 + n2;
System.out.println("Sum of these numbers:" + sum);
}
}
Program Completed
Kindly Refer to the Attachment :)
Hope it Helps :)
Keep learning!
Be brainly!