how to create a java function that makes random math problems. -
i trying create java function creates random math problems. want have function create problem onclick show answer.
is necessary use random int ?
i thinking making i random number using in math problems... appreciated.
private int rando(int i) { random randomgenerator = new random(); int randomint = randomgenerator.nextint(); = randomint; return rando(); } public static int add(int i, int i) { int = i+i; return a; } b1.addactionlistener(new actionlistener() { public void actionperformed(actionevent e){ string b = "click answer"; b1.settext(b.tostring()); jl.settext(prob.tostring()); } });
how about
//or whatever numbers want here int mylow = -10; int myhigh = 10; public int randbetween(int low, int high){ return (int) math.round(math.random() * (high - low)) + low; } public string makeproblem(atomiclong answer){ int = randbetween(mylow, myhigh); int b = randbetween(mylow, myhigh); double result; char operator; switch(randbetween(1,4)){ case 1: operator = '+'; result = + b; break; case 2: operator = '-'; result = - b; break; case 3: operator = '*'; result = * b; break; case 4: operator = '/'; result = (double) / b; break; default: operator = '\0'; result = double.nan; } answer.set(double.doubletolongbits(result)); return string.format("%d %c %d = ?",a,operator,b); } public void yourfunction(){ //whatever need before atomiclong outvariable = new atomiclong(); string question = makeproblem(outvariable); double answer = double.longbitstodouble(outvariable.get()); //whatever need after }
Comments
Post a Comment