fork download
  1. /* Question 1
  2. Write a Java program that does the following:
  3. Uses the Scanner class to take two integer numbers from the user.
  4. Displays a message asking the user to enter the two numbers.
  5. Performs the following four arithmetic operations and print result of each operation */
  6. import java.util.*;
  7. public class Main {
  8. public static void main (String[]args){
  9. Scanner in = new Scanner (System.in);
  10. System.out.println("Enter two numbers");
  11. int x = in.nextInt();
  12. int y = in.nextInt();
  13. System.out.println(x+" + "+y+" = "+(x+y));
  14. System.out.println(x+" + "+y+" = "+(x-y));
  15. System.out.println(x+" + "+y+" = "+(x*y));
  16. System.out.println(x+" + "+y+" = "+(x/y));
  17. }
  18. }
Success #stdin #stdout 0.17s 58760KB
stdin
20 10
stdout
Enter two numbers
20 + 10 = 30
20 + 10 = 10
20 + 10 = 200
20 + 10 = 2