-
Loop inside a switch
Just a simple question :
If you have a switch statement that tests a charand whatever letter it is how do you make a loop so that it prints out lets say 30 times?
can you do it without using something else like:
while this is less that 31
print out this
-
I'm not sure I get exactly what you're trying to do here. If you don't get a decent answer by others, you may want to expand on your explanation a bit and even post a code attempt at solving it.
Much luck!
-
Why would you even need a switch?
Code:
public static void printchar(char c) {
for(int i = 0; i < 30; i++)
System.out.println(c);
}
-
Yes, why are embedded a loop in switch. It's not a good design at all, if someone else read your code will confuse, and difficult to understand.
As m00nchile suggest in the above post, do that looping stuff in a different method, and call the appropriate method in case statement. There is no limitation, you can use many number of methods within your classes.