Write a Java program to print the sum, multiply, subtract, divide and remainder of two numbers


Introduction

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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Javaexcercise {
  5.  
  6. public static void main(String[] args) {
  7. Scanner in = new Scanner(System.in);
  8.  
  9. System.out.print("Input 1st number: ");
  10. int num1 = in.nextInt();
  11.  
  12. System.out.print("Input 2nd number: ");
  13. int num2 = in.nextInt();
  14.  
  15.  
  16. System.out.println("Addition of two numbers: " + num1 + " + " + num2 + " = " +
  17. (num1 + num2));
  18.  
  19. System.out.println("subtraction of two numbers: " +num1 + " - " + num2 + " = " +
  20. (num1 - num2));
  21.  
  22. System.out.println("Multiplication of two numbers: "+ num1 + " x " + num2 + " = " +
  23. (num1 * num2));
  24.  
  25. System.out.println("Division of two numbers: " + num1 + " / " + num2 + " = " +
  26. (num1 / num2));
  27.  
  28. System.out.println("Remainder of two numbers: "+ num1 + " mod " + num2 + " = " +
  29. (num1 % num2));
  30. }
  31.  
  32. }

Result

java techstudy.org

     





Related Topics




Popular Posts