I have a method that helps me to validate variables int
, but when I pass them from C ++ to Java the ignore
and clear
methods do not work for me.
Is there any equivalent to those functions in Java ?
int ValidaInt(){
int numero;
if (cin>>numero)
{
return numero;
}
else
{
cout<<"El caracter digitado no corresponde a un numero\n";
cout<<"Por favor digite un numero:\n";
cin.clear(256,"\n");
cin.ignore();
validaInt();
}
}