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
JavaBot
JavaBot•3w ago
⌛ This post has been reserved for your question.
Hey @boosledorf! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot•3w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
boosledorf
boosledorfOP•3w ago
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?
ayylmao123xdd
ayylmao123xdd•3w ago
in this example it takes both statements to the same output
ayylmao123xdd
ayylmao123xdd•3w ago
Baeldung
Java Switch Statement | Baeldung
A detailed tutorial about the Switch statement in Java and its evolution over time.
ayylmao123xdd
ayylmao123xdd•3w ago
you can read more about it here theres the exact example you got but with animals instead
JavaBot
JavaBot•3w ago
💤 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.

Did you find this page helpful?