Computer Science, asked by kuldeepsachdev3770, 1 year ago

how to add two numbers by getting the value from the user in java program?

Answers

Answered by satyasharma52
1
Here we will see two programs to add two numbers, In the first program we specify the value of both the numbers in the program itself.
Answered by atrs7391
1

Your program:

package com.company;

import java.util.Scanner;

class test

{

   public static void main(String[] args)

   {

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter first number: ");

       double n1 = sc.nextDouble();

       System.out.println("Enter second number: ");

       double n2 = sc.nextDouble();

       long n3 = (long)n1+(long)n2;

       System.out.println("The sum of the numbers: "+n3);

   }

}

Similar questions