java - Solve algebraic Equation -


this question has answer here:

i've created random question generator. questions in form: x=3/random number. problem program never recognizes fact user's answer correct. i've made print out answer , copy answer input (text pane), yet prints out "wrong."

private void jbutton1actionperformed(java.awt.event.actionevent evt) {                                               //generates random value n (2 decimal plcae)        double nmin = 1.0;//minimum     double nmax = 38.6;//maximum     random rn = new random();       double nrand = nmin + (nmax - nmin) * rn.nextdouble();      //calculates corresponding value of v     string x = string.format("%.2f", 3/nrand );     double nans = double.parsedouble(x);//corresponding value of c     check.settext(x);      //displays question     question.settext("n = " + string.format( "%.2f", nrand ) + "     v = ?");//question     string answer = answerinput.gettext();     double nusera = double.parsedouble(answer);     //checks user's answer     if(x.equals(answer)) {         check.settext("correct");     }         else         check.settext("wrong");     }                                       

to compare if string equals in java have use .equals() function, not ==. this:

s1.equals(s2); 

supposing s1 , s2 strings have change condition to:

if(x.equals(answer)) 

i expect helps you!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -