123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
-
- import java.util.Scanner;
-
- public class ShortCalculator {
- private int x;
- private int y;
-
- public ShortCalculator(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
-
- System.out.println("Enter two numbers between 0 and 65535");
- System.out.println("Input the first number:");
- int n1 = reader.nextInt();
- System.out.println("Input the second number:");
- int n2 = reader.nextInt();
- ShortCalculator calc = new ShortCalculator(n1, n2);
-
- calc.printLine("Sum", calc.sum());
- calc.printLine("Difference", calc.difference());
- calc.printLine("Product", calc.product());
- calc.printLine("Quotient", calc.quotient());
- calc.printLine("Remainder", calc.remainder());
- }
-
- public short sum() {
- return (short) (x + y);
- }
-
- public short difference() {
- return (short) (x / y);
- }
-
- public short product() {
- return (short) (x * y);
- }
-
- public short quotient() {
- return (short) (x / y);
- }
-
- public short remainder() {
- return (short) (x % y);
- }
-
- public void printLine(String operation, short value) {
- System.out.println(operation + ": " + value);
- }
- }
|