Forum Stats

  • 3,759,510 Users
  • 2,251,557 Discussions
  • 7,870,689 Comments

Discussions

Create a hasNext within a do-while block

The main idea is to avoid exceptions by using either hasNext or the default option of the switch clause.

I know the easiest way to handle exceptions is using a try-catch block though do not what to use it.

When getting input from the user. it's supposed to type a number. Using the hasNextByte method would be:

System.out.print ("Type a byte: ");

if (scanner.hasNextByte()) {
    System.out.println ("You've typed a byte");
}

else {

    System.out.println ("Ain't a byte");

}

Now I wonder how to add this clause in a do-while block.

ANy help'd be fantastic !!

Thank y'all !!!!!