I have two while loops where one is taking the odd numbers between 50 to 100 and the other is taking the even numbers from the same between 50 to 100. It is printing out well and it works but my professor wants me to transform it into one while loop instead of two. I am having trouble with it because I am using the print statement before in order so it fits into when the numbers go in.
int e = 50;
int o = 51;
System.out.print("Even numbers between 50 and 100: 50,");
while (e <= 98){
e += 2;
if (e%2 == 0){
System.out.print(e + ",");
}
}
System.out.print("\nOdd numbers between 50 and 100: 51,");
while (o <= 97){
o+= 2;
if (e%1 == 0) {
System.out.print(o + ",");
}
}
Even numbers between 50 and 100: 50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,
Odd numbers between 50 and 100: 51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,
The output looks like this right now, but I need to be able to do it with just one loop instead