-
-
Save Noia/3681798 to your computer and use it in GitHub Desktop.
AutoCalc by joshellis625
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* I have not compiled this, so I make no promises that I will work as expected... | |
*/ | |
public class AutoCalc { | |
private int x = 0, y = 0; | |
private final Scanner scanner = new Scanner(System.in); | |
public static void main(String[] args) { | |
new AutoCalc().read().print(); | |
} | |
public AutoCalc print() { | |
System.out.printf("Let's do some math using the numbers %d and %d!%n",x,y); | |
System.out.println(); | |
System.out.printf("The sum of %d and %d is %d%n",x,y,x+y); | |
System.out.printf("The difference between %d and %d is %d%n",x,y,x-y); | |
System.out.printf("%d divided by %d is %f%n",x,y,x/y); | |
System.out.printf("%d times %d is %d",x,y,x*y); | |
return this; | |
} | |
public AutoCalc read() { | |
while(true) { | |
try { | |
System.out.print("Input first number: "); | |
x = scanner.nextInt(); | |
System.out.print("Input second number: "); | |
y = scanner.nextInt(); | |
System.out.println(); | |
return this; | |
} catch (InputMismatchException | NoSuchElementException e) { | |
System.out.println("Thats not a number...or something"); | |
} | |
} | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment