Código para garantir que vai ler o que se espera do teclado

10 views
Skip to first unread message

Petrônio

unread,
Oct 28, 2014, 9:26:48 AM10/28/14
to poo_red...@googlegroups.com

public static void main(String[] args) {

// Declare File object

 

// initialize the scanner

Scanner scan = new Scanner(System.in);

int x = 0;

// iterate through the tokens

while(scan.hasNext()){

// print int tokens

if(scan.hasNextInt()){

x = scan.nextInt();

break;

}

else{

System.out.println(scan.next());

}

 

}

scan.close();

System.out.println("Número lido"+ x);

 

}

Reply all
Reply to author
Forward
0 new messages