View Single Post
  #3 (permalink)  
Old 08-01-2007, 05:25 AM
yiweiang yiweiang is offline
Member
 
Join Date: Aug 2007
Posts: 15
yiweiang is on a distinguished road
Hi there,

If i were to do it, i would create another class with a method run() that returns a integer. Now i can get the main method to create an instance of this class.Create a loop that will call the method run().

public static void main(string Args[])
{

Game myGame=new Game();
while(x==0)
{
myGame.run();
}
}


********

public class Game()
{

public int run()
{

//your code goes here. This code below runs after the game completes

System.out.println("Would you like to play again?" 0 for yes, 1 for no)
int decision=myInput.nextInt(); //remember to import Scanner method

return decision;
}
}
When the method run completes, you decide in the programming logic for it to return either 1 or 0.



So if it's zero, it runs again. Otherwise it stops.
Reply With Quote