|
variable's variable? Edited: Arrays (in Java)
Link |
by
|
|
Well, the problem is that I need many of variable. For example, int point0, point1, point2, ... point500)Therefore I got to initiate them. What I thought was, "This is such ineffective way of programming. Then I tried to make the program initiate variable by itself. To produce massive work, we use looping. for(int amount=1; amount<=500; amount++){int xxx}The question, what should we fill xxx? Is there any other way to do massive initiation of same data type? P.S.: I know it may sounds ridiculous, but an idea is an idea. Edited:I use an array ( int win[]) to store the massive amount of of variable.Thanks for reading. P.S.: It was ridiculous! -Problem 1 Solved- Problem 2Now that I've stored some numbers on an array ( win[])I'd like to display the integer in percentage Therefore I typed: What happened on the output is: All the percentage ( percentage[b]) are zeroEven that there are not zero amount on win[b]Why is it? How to solved it? (have the percentage of number stored at win[b])
Dream ends when we wake up and life ends when we die.
What's the different? |
|
Re: variable's variable? Edited: Arrays (in Java)
|
|
Multiply win[b] by 100 before you multiply, or divide it by 5 rather than 500, or use floating point numbers. i.e. percentage[b] = (win[b] * 100 / round);or float percentage[]; // or somethingOr.. um.. something along those lines. I'm not proficient in Java, but I think these solutions would probably solve your issue. |
|
Re: variable's variable? Edited: Arrays (in Java)
Link |
by
|
|
Float or even Double! That's it, int would be inappropriate variable data type, how come I didn't notice... Moreover, If it is not multiplied by 100 how could I call that "percentage". Ah... Thanks zehippo. -Problem 2 Solved-
Dream ends when we wake up and life ends when we die.
What's the different? |