lundi 3 juin 2019

How do you initilize a variable inside a loop

My code is supposed to keep looping until a valid input is given, ie: if a letter is given it will loop, but if a valid number is given, the code should store it into cSec. Is there anyway to do this?

    byte cSec;
    boolean contCSec = true;
    while(contCSec == true) {
        System.out.println("Enter course section: ");
            cSec = sc.nextByte();
        if(cSec>0)
            contCCode = false;
    }

cSec can't be used outside the loop.

Aucun commentaire:

Enregistrer un commentaire