Advertisement
JustACodingStudent

Basic Two-Value Calculator

Feb 10th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package arithmetic;
  2.  
  3.  import java.util.Scanner;
  4. public class Arithmetic {
  5.  
  6.     public static void main(String[] args) {
  7. //     New scanner for input created  
  8.         Scanner input = new Scanner (System.in);
  9. //     Creation of variables to calculate; x and y being factors,ans being the answer.
  10.         int x, y, ans;
  11.         double a, b, sol;
  12. //     Inputting of values to factors.
  13.         System.out.print("Enter the first whole number value: ");
  14.         x = input.nextInt();
  15.         System.out.print("Enter the second whole number value: ");
  16.         y = input.nextInt();
  17.         a = x;
  18.         b = y;
  19. //     Header for integer arithmetic  
  20.         System.out.println("\nIntegers:  \n");
  21. //     Addition  
  22.         ans = x + y;
  23.         System.out.println(x + " plus " + y + " = " + ans);
  24. //     Subtraction
  25.         ans = x - y;
  26.         System.out.println(x + " minus " + y + " = " + ans);
  27. //     Multiplication
  28.         ans = x * y;
  29.         System.out.println(x + " times " + y + " = " + ans);
  30. //     Division
  31.         ans = x / y;
  32.         System.out.println(x + " divided by " + y + " = " + ans);
  33. //     Modulus Division
  34.         ans = x % y;
  35.         System.out.println("The remainder of " + x + " divided by " + y + " is " + ans);
  36.        
  37. //     Doubles
  38.         System.out.println(" \nDoubles: \n");
  39.         sol = a + b;
  40.         System.out.println(a + " plus " + b + " = " + sol);
  41.         sol = a - b;
  42.         System.out.println(a + " minus " + b + " = " + sol);
  43.         sol = a * b;
  44.         System.out.println(a + " times " + b + " = " + sol);
  45.         sol = a / b;
  46.         System.out.println(a + " divided by " + b + " = " + sol);
  47.         sol = a % b;
  48.         System.out.println("The remainder of " + a + " divided by " + b + " is " + sol);
  49.     }
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement