How to create a back button with integers (VERY NEW)

I’m making a little program that is a little assistant, right now all he does is calculate things, but after you do something the build ends and to do it again you have to go through dialogue , id like a back button to go back to the menu.

import java.util.Scanner;


public class idk77 {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int num1=1;
        int num2=2;
        int num3=3;
        int num4=4;
        int end=0;
        int q2=0;
        int q3=0;
        int q4=0;
        int q5=0;
        int q6=0;
        int q7=0;
        int q8=0;
        int q9=0;
        int q10=0;
        int q11=0;
        int q12=0;
        int q13=0;
        int q14=0;
        int q15=0;
        int q16=0;
        int q17=0;
        int q18=0;
        int q19=0;
        int q20=0;
        int add1=0;
        int add2=0;
        int sub1=0;
        int sub2=0;
        int mult1=0;
        int mult2=0;
        int div1=0;
        int div2=0;
        int add=0;
        int sub=0;
        int mult=0;
        int div=0;
        
                
        
        
        
        System.out.println("Hello! \n1. Hello! \n2. Who are you? \n3. Go away!");
        int q1=scan.nextInt();
        
        /*
        Using methods might be more effcient but i dont know enough to make
        it any better
        
        Currently only a calculator but hopefully later add more fun features
        */
        
       
        if(q1==num1)
        {
        // 1 (Repeats, next option will not include 1 to continue the story)
        System.out.println("Hello! \n1. Who are you?");
         q2 = scan.nextInt();
        }
                
        if(q1==num2)
        {
        //2
        System.out.println("Im Cody! \n1. What do you do Cody?");
         q3=scan.nextInt();
        }
        
        if(q1==num3){
        //3 allows more options like 1.
        System.out.println("Ok \n1. Wait! \n2. Goodbye");
         q4=scan.nextInt();
        }
        
        
        if(q2==num1){
            System.out.println("Im Cody! I am your friendly assistant. \n 1. What can you assist me with?");
         q5=scan.nextInt();
        }
        
        if(q3==num1){
            System.out.println("I assist you with things \n 1. What can you assist me with?");
         q6=scan.nextInt();
        }
        
        //Fix q7 and then work on goodbye (remove it probably) after that continue
        if(q4==num1){
            System.out.println("Yes? \n1.Who are you?");
         q7=scan.nextInt();
        }
        
        /*            figure out later (goodbye!)
        if(q4==num2)
            System.out.println("");
        */
        
        if(q5==num1){
            System.out.println("I can add, subtract, multiply, and devide numbers \n 1. I'd like to try!");
         q8=scan.nextInt();
        }
        
        if(q6==num1){
            System.out.println("I can add, subtract, multiply, and devide numbers \n 1. I would like to try!");
         q8=scan.nextInt();
        }
        //Note for March 17: fix double q7
        
        
        
        if(q8==num1){
            System.out.println("Ok! What do you need? \n 1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Division  ");
         q11=scan.nextInt();
        }
        
        
        //Q11
        if(q11==num1){
            System.out.println("Whats your first number?");
         q12=scan.nextInt();
        
        System.out.println("Whats your second number?");
        q13=scan.nextInt();
        
        add = q12+q13;
        System.out.println(q12+" plus "+q13+" equals "+add);
        }
        if(q11==num2){
            System.out.println("Whats your first nunmber?");
         q14=scan.nextInt();
        
        System.out.println("Whats your second number?");
         q15=scan.nextInt();
        
        sub = q14-q15;
        System.out.println(q14+" minus "+q15+" equals "+sub);
        }  
        if(q11==num3){
            System.out.println("Whats your first number?");
         q16=scan.nextInt();
         System.out.println("Whats your second number?");
         q17=scan.nextInt();
         mult = q16*q17;
         System.out.println(q16+" times "+q17+" equals "+mult);
            
        }
        if(q11==num4){
            System.out.println("Whats your first number?");
         q18=scan.nextInt();
         System.out.println("Whats your second number?");
         q19=scan.nextInt();
         div = q18/q19;
         System.out.println(q18+" divided by "+q19+" equals "+div);
        
        }
        
        //Here is where i want to add a option (1. Go back) to go back to the menu
  
        
        
        
    } 
    
    
    
    
}


/*

*/

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

Pre-formatted-text

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.