confused about a question on my practice exam with switch and case
public class Test {
public static void main(String[] args) {
for (int i = 1; i <= 7; i++) {
switch (i) {
case 1:
case 2:
System.out.print("A");
if (i % 2 == 0) {
System.out.print("B");
}
break;
case 3:
case 4:
System.out.print("C");
if (i == 4) {
System.out.print("D");
} else {
System.out.print("E");
}
break;
case 5:
System.out.print("F");
break;
case 6:
case 7:
System.out.print("G");
if (i % 3 == 0) {
System.out.print("H");
}
break;
}
}
}
}
7 Replies
⌛
This post has been reserved for your question.
Hey @boosledorf! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Please format your code to make it more readable. For java, it should look like this:
its a bunch of cases but it will say somthing like
case 1:
case 2:
System.out.print("A")
but why does that print a for case 1 wouldnt it do nothing?
in this example it takes both statements to the same output
Baeldung
Java Switch Statement | Baeldung
A detailed tutorial about the Switch statement in Java and its evolution over time.
you can read more about it here
theres the exact example you got but with animals instead
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.