I was making a basic nooby java tribe game, and I needed a way to return to main menu. Can anyone tell me of any methods? This is my current code (incomplete)
I want it to return to main menu if a certain number is entered after the stats are displayed.

import java.util.Random;
import java.util.Scanner;
public class SurvivalIsland {

	 * @param args
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in);
		Scanner user_input = new Scanner( System.in );
int food;
int water;
int housing;
int tech;
int pop;
int atk;
int def;
int x;
int karma;
int farmlevel;
int choice;



	String tribename;
	System.out.print("Enter your tribe's name: ");
	tribename = user_input.next( );
	System.out.println("You are the leader of the "+tribename+" Tribe");
	System.out.println("Enter 1 to See your tribes current stats");
	System.out.println("Enter 2 to use action points");
	System.out.println("Enter 3 to sleep");
	choice = in.nextInt();

	case 1:
			System.out.println("Your Tribes Stats");
			System.out.println("Population ("+pop+")");
			System.out.println("Water Supply ("+water+")");
			System.out.println("Housing Level ("+housing+")");
			System.out.println("Technological Level ("+tech+")");
			System.out.println("Food Supply ("+food+")");


	}//main method


Edited 5 Years Ago by gbatemper: n/a

One way to return to an earlier piece of code is to use a loop:

begin loop
 do menu stuff
 check user's response
 do what user wanted
 go back to beginning of loop <<< this can be automatic or done by continue statement
end loop

Thanks for the help! I got it to work!

Edited 5 Years Ago by gbatemper: n/a

I want to prevent it from going negative and stay at 0.

At what point do you want to stop it?
Before it goes negative: test if the amount to subtract > the amount available
If it is, don't subtract it. Or set to 0 and have a deficit amount unsupplied
Or after: test if result is < 0 and set to 0

This question has already been answered. Start a new discussion instead.