Skip to content

@Noia / forked from anonymous/

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
AutoCalc by joshellis625
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(;
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.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();
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
Something went wrong with that request. Please try again.