lundi 25 septembre 2017

I need to get two separate lines for evens and odds, but the catch is, I can use only one while loop

This is my code:

int numb = 50;
    int odd;
    int even;
    while (numb <= 100 )
    {
        if (numb % 2 == 0)
        {
            even = numb;
            System.out.println(even);
            System.out.print(", ");
            numb++;
        }
        System.out.println("");
        if(numb % 2 != 0)
        {
            odd = numb;
            System.out.print(odd);
            System.out.print(", ");
            numb++;
        }
    }

So far, it prints two columns of answers but i need to separate rows of evens and odds. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire