The code you posted is Java. This is a Javascript forum, but I happen to be a Java programmer too....
PHP Code:
import java.util.*;
import java.lang.Math;
// Note: java.lang.Math has a method named random()... to make things less confusing we'll rename the class to "MyGame"
class MyGame
{
// instance variable declaration
private int snumber;
private Scanner scan;
// Constructor.
public MyGame()
{ // Initialize variables here.
snumber = -1;
scan = new Scanner(System.in);
}
// The game loop.
public void runGame()
{
while (snumber != 0)
{
System.out.print("Enter a value of n or '0' to exit: ");
snumber = scan.nextInt();
if ( (snumber >= 100) && (snumber <= 500) )
{ // Play your game here.
// Note: this line calls the showNumber function which outputs the value of the Instance variable "snumber"
showNumber();
} else if (snumber != 0) // Avoids the exit case of Zero
{ // Oops, bad number, try again.
System.out.println("So sorry. The value must be between 100 and 500 inclusively.");
}
}
// Nothing to do after this line, the program will exit.
System.out.println("Thanks for playing, and make it a great day! :)");
}
// Main method get's called from a static context.
public static void main( String[] args)
{ // Create a new MyGame object.
MyGame application = new MyGame();
// Start playing the game.
application.runGame();
}
// Output the current n value.
public void showNumber()
{ // outputs the number stored in the instance variable "snumber"
System.out.println("n is " + getNumber());
}
// returns the snumber value
public int getNumber()
{
return snumber;
}
}
Copy and paste this code into your text editor.
Save the file as "MyGame.java"
Compile via: javac MyGame.java
Run via: java MyGame
Moderator's note: Please move this to the Java / JSP forum.