New to java, need to learn how to store multiple Doubles with the same name -
i new java , want learn how store different values double. code asks user how many times calculate equation, each time entering different values. program takes numbers entered plugs them formula , produces answer. problem comes trying take answers generated , totaling them, have no idea how this.
double wt, rep, t = .0333333, rm = 0, lts; string initwt, initrep, lt; lt = joptionpane.showinputdialog ( "how many lifts calculate" ); lts = integer.parseint (lt); if (lts < 0){ joptionpane.showmessagedialog (null, "you entered invalid number"); system.exit(0); } while (lts > 0){ initwt = joptionpane.showinputdialog ( "please enter inital weight" ); wt = integer.parseint (initwt); initrep = joptionpane.showinputdialog ( "please enter amount of reps" ); rep = integer.parseint (initrep); /* want take each rm value, , store it, can total later.*/ rm = wt * rep * t + wt; joptionpane.showmessagedialog (null, "your 1 rep max " + rm ); lts --; } int dialogbutton = joptionpane.showconfirmdialog(null, "would see total?", "please choose one", joptionpane.yes_no_option); /* want bring rm values , total them display here */ if (dialogbutton == joptionpane.yes_option){ joptionpane.showmessagedialog (null, "your combined totals " + rm ); } else if (dialogbutton == joptionpane.no_option){ system.exit(0); } }
you can't store multiple values same name. can use array:
double[] doubles = new double[/* size */];
and access it:
doubles[0] = 5.0; system.out.println(doubles[0]); // 5.0
or have multiple doubles:
double d1 = 5.0; double d2 = 3.0; system.out.println(d1); // 5.0
or can use collection:
list<double> doubles = new arraylist<double>();
and access it:
doubles.add(5.0); system.out.println(doubles.get(0)) // 0 index, prints 5.0
Comments
Post a Comment