Write a Java program to print the sum, multiply, subtract, divide and remainder of two numbers
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
import java.util.Scanner; public class Javaexcercise { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input 1st number: "); int num1 = in.nextInt(); System.out.print("Input 2nd number: "); int num2 = in.nextInt(); System.out.println("Addition of two numbers: " + num1 + " + " + num2 + " = " + (num1 + num2)); System.out.println("subtraction of two numbers: " +num1 + " - " + num2 + " = " + (num1 - num2)); System.out.println("Multiplication of two numbers: "+ num1 + " x " + num2 + " = " + (num1 * num2)); System.out.println("Division of two numbers: " + num1 + " / " + num2 + " = " + (num1 / num2)); System.out.println("Remainder of two numbers: "+ num1 + " mod " + num2 + " = " + (num1 % num2)); } }
Result:
Input 1st number: 50
Input 2nd number: 4
Addition of two numbers: 50 + 4 = 54
subtraction of two numbers: 50 - 4 = 46
Multiplication of two numbers: 50 x 4 = 200
Division of two numbers: 50 / 4 = 12
Remainder of two numbers: 50 mod 4 = 2
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
Result:
Input 1st number: 50
Input 2nd number: 4
Addition of two numbers: 50 + 4 = 54
subtraction of two numbers: 50 - 4 = 46
Multiplication of two numbers: 50 x 4 = 200
Division of two numbers: 50 / 4 = 12
Remainder of two numbers: 50 mod 4 = 2
need an explanation for this answer? contact us directly to get an explanation for this answer