I really didn't think to much about using the loop method and i don't think it made it more complicated. Here's my code:
package com.crash.java;
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Main mainObject = new Main();
execute();
}
public static void execute() {
Main mainObject = new Main();
Scanner scanner = new Scanner(System.in);
int num1, num2, total;
String opr, option;
System.out.println("Input 2 numbers: ");
num1 = scanner.nextInt();
num2 = scanner.nextInt();
scanner.nextLine();
System.out.println("Now the operation: ");
opr = scanner.nextLine();
if(opr.equals("+")) {
total = num1 + num2;
System.out.println("Total: " + total);
}else if(opr.equals("-")) {
total = num1 - num2;
System.out.println("Total: " + total);
}if(opr.equals("/")) {
total = num1 / num2;
System.out.println("Total: " + total);
}if(opr.equals("*")) {
total = num1 * num2;
System.out.println("Total: " + total);
}
System.out.println();
//Ask if you want to terminate or make another calculation
System.out.println("Do you want to reset? Yes or No");
//Option Input
option = scanner.nextLine();
System.out.println();
//Checking whether the program should reset or terminate
if(option.equals("Yes") || option.equals("yes")) {
mainObject.reset();
}else{
return;
}
}
public static void reset() {
Main mainObject = new Main();
mainObject.execute();
}
}
Basicly what i thought when writting this was that i need something to make the whole program run again so i created a method to execute the code and then one that if called would run the execute method again, so i gues in the end is in fact a loop.
I didn't think it was that difficult to use this method since it took me like 5 minutes but i think the reason for that is that right now i've been working alot with object-oriented coding and with multiple methods. Anyway with all this discussion we've found out 2 different ways of doing this, one with a do while loop and one using an execute and reset method.