i'm making calculator in java , i'm trying make possible add/subtract/multiply/divide more 2 numbers using more 1 math operator @ time. trying put numbers in different places of array, reason puts of numbers @ place 0. not sure why happening because made loop adds 1 "i" should change place of array. (also numdisplay jtextfield)
add.addactionlistener(new actionlistener() { public void actionperformed(actionevent event) { (int = 0; < array.length; i++) { array[i] = numdisplay.gettext(); adddouble = double.parsedouble(array[i]); system.out.println(array[i] + " @ place " + i); numdisplay.settext(""); break; } } });
for (int = 0; < array.length; i++) { ... break; // breaks after first iteration } you're breaking out of loop after first iteration, you'll have 1 number in array.
i tried remove break added zeroes every other place automatically
you have array[i] = numdisplay.gettext(); first , @ end of loop have numdisplay.settext("");. on subsequent iterations tries convert empty string double, , ends getting zero.
what want every time press add button, add number i'm trying add array.
a list<double> better here. can list.add(somedoublevalue) inside event listener. otherwise need keep track of total number of elements added far array , insert new element @ appropriate location (if there room).
Comments
Post a Comment