Program:
Output:
enter first number
5
enter second number
6
11.0
import java.util.*;
public class apple
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double i,j,k;
System.out.println("enter first number");
i=sc.nextDouble();
System.out.println("enter second number");
j=sc.nextDouble();
k=i+j;
System.out.println(k);
}
}
Output:
enter first number
5
enter second number
6
11.0
note:
you can build multiplication,subtraction,division,etc by just chaning the operator (+,-,*,/)
In this program we are using scanner class for dynamically entering the values of different numbers that's why importing java.util package
No comments:
Post a Comment