Advertisement
virtualideaz

Calculator.java

Apr 4th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. //
  2. //this is a calculator that computes basic operations of math
  3. //
  4.  
  5. import java.util.Scanner;
  6. public class Calculator {
  7.     static Scanner sc = new Scanner(System.in);
  8.     public static void main(String [] args) {
  9.         //create variables
  10.         double a;
  11.         double b;
  12.         //input
  13.         System.out.print("Enter a : ");
  14.         a = sc.nextDouble();
  15.         System.out.print("Enter b : ");
  16.         b = sc.nextDouble();
  17.        
  18.         //basic operations
  19.         double add = a+b;
  20.         double subtract = a-b;
  21.         double multiply = a*b;
  22.         double divide = a/b;
  23.        
  24.         //outputs
  25.         System.out.println("Sum : " + add);
  26.         System.out.println("Difference : " + subtract);
  27.         System.out.println("Product : " + multiply);
  28.         System.out.println("Quotient : " + divide);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement