Generate two random numbers

I writing a "Math Game program" which does the follow:
Generate random two operand problems.
Allow to the user to enter the solution
Each time the user gets a correct result then display a random encouraging message. Similar for incorrect attempts.

This program works good in BlueJ, BUT when I write those codes in NetBeans, My problems are:
The two random operands always start with 0.
If statement don't get the properly result.
I set the For loop in 3, but it don't end.

Any suggestions would be great.
Thank you.

[code]import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class Game extends Applet implements ActionListener {
Label prompt;
TextField input;
int numb1;
int numb2;
int player;
int answer;
Label status;

public void init()
prompt = new Label( "What is " + numb1 + " + " + numb2 + "?" );
add( prompt );

input = new TextField( 10);
add( input );

input.addActionListener( this );

status = new Label("Status");

public void paint (Graphics g)
setBackground (Color.ORANGE);

public void actionPerformed( ActionEvent e )
numb1 = (int)(Math.random()*10)+1;

numb2 = (int)(Math.random()*10)+1;

player = Integer.parseInt(e.getActionCommand());

answer = (numb1 + numb2);

if (player == answer)
status.setText("Incorrect answer, please try again");



  • Math game is the dun thing to play and you can also explore these games by visiting this site cool math game junction . And this game is free of cost on your android phone , so why don't you try this right away .

Sign In or Register to comment.

Howdy, Stranger!



In this Discussion