Computer Science, asked by shahpavitra207, 4 months ago

Write Java program to subtract one number from another and

print the difference.​

Answers

Answered by kalivyasapalepu99
0

Java program to perform basic arithmetic operations of two numbers. Numbers are assumed to be integers and will be entered by the user.

 

Ad by Valueimpression

This Java program asks the user to provide integer inputs to perform mathematical operations.

Scanner class and its functions are used to obtain inputs, and println() function is used to print on the screen.

Scanner class is a part of java.util package, so we required to import this package in our Java program.

We also required to create a object of Scanner class to call its functions.

import java.util.Scanner;

 

public class JavaProgram

{

   public static void main(String args[])

 {

   int first, second, add, subtract, multiply;

   float devide;

   Scanner scanner = new Scanner(System.in);

   System.out.print("Enter Two Numbers : ");

   first = scanner.nextInt();

   second = scanner.nextInt();

   add = first + second;

   subtract = first - second;

   multiply = first * second;

   devide = (float) first / second;

   System.out.println("Sum = " + add);

   System.out.println("Difference = " + subtract);

   System.out.println("Multiplication = " + multiply);

   System.out.println("Division = " + devide);

 }

}

output of the program

Enter Two Numbers : 12

5

Sum = 17

Difference = 7

Multiplication = 60

Division = 2.4

Similar questions