mardi 22 novembre 2016

Validate scanner user input in if statement WITHOUT variables

Purpose is to reduce the number of variables so instead of making many variables I want to do something like this:

Scanner scnr = new Scanner(System.in); 

int number = 0;

scnr.nextInt();  

if (((scnr.nextInt() >= 4) && (scnr.nextInt() <=10))) 
{
   number = scnr.nextInt();
}

Instead of

Scanner scnr = new Scanner(System.in); 

int number = 0;
int storeNum = 0;

number = scnr.nextInt();  

if (((number >= 4) && (number <=10))) 
{
   storeNum = scnr.nextInt();
}

Aucun commentaire:

Enregistrer un commentaire