arrays - Count a variable in a while-loop in Java -
I have this piece of code:
while (i> gt; 0) {System .out.println (M + i); Do nothing / i--; }
and we found the input: i
, m1
, m2
, ... we say : i = 2
, m1 = test
, m2 = blabla
I want m1
To be dependent on i
, m2
and M3
should be printed when I = 2 "Blaala" when I = 1 "test" Must be printed. I tried m + i
but the output is m1
, the value is not there.
Can anyone explain why m + i
does not work and why it costs m1
or m
Not using? And anyone has the idea of how to fix it?
It looks like you're trying to do some types of switch statements like this: < / P>
int i = 2; String m 1 = "test"; String M2 = "Blubber"; While (i & gt; 0) {System.out.println (i); // will print the number that I currently switch to (i) {case 2: System.Out.Println (m2); // If I have 2 breaks then the M2 variable will be printed; Case 1: System.Out.Println (M1); // If I have 1 break, then the M2 variable will print; Default: Break; // nothing else, nothing else will be printed) i--; }
Should be what you are searching for. However, there are several things to note:
- Variables in Java, and how to use them
-
System.Out.Println
, and What does this do. -
switch
and / orfor
Comments
Post a Comment