Java Scanner nextByte() MethodThe nextByte() is a Java Scanner class method which is used to scan the next token of the input as a Byte. There is two different types of Java nextByte() method which can be differentiated depending on its parameter. These are:
nextByte() MethodThis is a Java Scanner class method which is used to scan the next token of the input as a Byte in the default radix. nextByte(int radix) MethodThis is an inbuilt method of Java Scanner class which is used to scan the next token of the input as a Byte in the specified radix. SyntaxFollowing is the declaration of nextByte() method: Parameter
ReturnsThe nextByte() method returns the Byte value scanned from the input. ExceptionsIllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed. IllegalArgumentException- It throws this exception if the specified radix is out of range. InputMismatchException- It throws this exception if the next token does not match the Integer regular expression, or is out of range. Compatibility VersionJava 1.5 and above Example 1Output: Enter the Number you want: 20 Output value: 220 Example 2Output: Enter Value of a: 55 Enter Value of x: 66 Enter Value of b: 88 Output: 88 Example 3Output: Not Found :JavaTpoint.com Found :13 Not Found :+ Found :13 Not Found := Not Found :26.0 Not Found :false Example 4Output: 85 53 -85 117 81 -122 Example 5Output: Not Found : 22 Not Found : Java Exception in thread "main" java.lang.IllegalArgumentException: radix:2050 at java.base/java.util.Scanner.setRadix(Scanner.java:1368) at java.base/java.util.Scanner.nextByte(Scanner.java:1998) at myPackage.ScannerNextByteExample5.main(ScannerNextByteExample5.java:10) Next TopicJava-scanner-nextdouble-method |