Math.Random() Java. Stay Constant -


I am trying to create a program / game where the user has to guess the number 1-100, I know that How to use random classes, but I have to use Math. Random (school project) for this. The issue I am facing is that I can not make the number in more than one estimate. A random number is generated, but it varies on every prediction, it renders null, any help is appreciated Thanks!

  Import java.awt. *; Import javax.swing. *; Import java.awt.event. *; Public Squared ActionListener {JFrame f; Container C; JPNl P; JTextField x; JLAB title, out; JButton Estimates; Int output, number; Public estimates () {f = new JFrame ("a number estimate!"); F.setSize (230,190); C = f.getContentPane (); P = new zpn (); Title = new JLABEL ("A number estimate (1-10):"); X = new JTextField (10); Estimate = New Payton ("Estimates"); Guess.addActionListener (this); Outside = new JLab (""); p.add (title); p.add (x); p.add (outside); p.add (estimates); c.add (p); f.show (); } Public Zero Action (Action Event Event) {if (event.getSource () == Estimate} {outp = (int) ((Math.random (* * 100 + 1)) Int numb = Integer ParseInt (x. gettext ();; if (numb and gt; outpace) {out.setText ("number is less");} if (numb & lt; outp) {out.setText ("number is high");} if (numb == outp) {out.setText ("true!");}}}}}    

Your problem is that every time you are reproducing a new random number they just guess put

  outp = (int) ((Math.random () * 100 + 1));   

Construct And you'll be set.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -