So I started learning java from the Head First Java book and stumbled upon a exercise.I need to rearrange these code snippets to obtain a output like this:
a-b c-d
The code snippets are:
if (x == 1) {
System.out.print("d");
x = x - 1
}
if (x == 2) {
System.out.print("b c");
}
if (x > 2) {
System.out.print("a");
}
while (x > 0) {
x = x - 1;
System.out.print("-");
int x = 3;
So I did something like this:
public class cc {
public static void main(String [] args) {
int x = 3;
while (x > 0) {
if (x == 2) {
System.out.print("b c");
}
if (x > 2) {
System.out.print("a");
}
if (x == 1) {
System.out.print("d");
}
x = x - 1;
System.out.print("-");
}
}
}
The output I am getting is :
a-b c-d-
What did I do wrong