Java Scanner nextByte() Method6 Nov 2024 | 3 min read The 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 |
The close() is a method of Java Scanner class which is used to closes this scanner. Syntax Following is the declaration of close() method: public void close() Parameter This method does not accept any parameter. Returns The close() method does not return any value. Exceptions NA Compatibility Version Java 1.5 and above Example 1 import java.util.Scanner; public class...
2 min read
Java Scanner () Method The () is a method of Java Scanner class which finds and returns the complete token from the scanner which is in using. There are three different types of Java Scanner () method which can be differentiated depending on its parameter. These...
3 min read
The remove() method of Java Scanner class is used when remove operation is not supported by this implementation of Iterator. Syntax Following is the declaration of remove() method: public void remove() Parameter This method does not accept any parameter. Returns The remove() method does not return any value. Exceptions UnsupportedOperationException- It will thrown exception if...
2 min read
The match() method of Java Scanner class is used to get the match result of the last scanning operation performed by this scanner. It returns true if it find the match result, otherwise returns false. Syntax Following is the declaration of match() method: public MatchResult match() Parameter This method does not...
2 min read
The delimiter() is a method of Java Scanner class which is used to get the Pattern which the Scanner class is currently using to match delimiters. Syntax Following is the declaration of delimiter() method: public Pattern delimiter() Parameter This method does not accept any parameter. Returns The delimiter() method returns the Pattern...
2 min read
Java Scanner hasInt() Method The hasInt() method of Java Scanner class is used to check if the token in this scanner's input can be interpreted as an int value using the Int() method. There is two different types of Java hasInt() method which can be differentiated...
5 min read
Java Scanner hasDouble() Method The hasDouble() is a method of Java Scanner class which is used to check if the token in this scanner's input can be interpreted as a double value using the Double() method. It returns true if the scanner's input can be interpreted...
3 min read
Java Scanner hasLine() Method The hasLine() is a method of Java Scanner class which is used to check if there is another line in the input of this scanner. It returns true if it finds another line, otherwise returns false. Syntax Following is the declaration of hasLine() method: public boolean...
2 min read
The locale() method of Java Scanner class is used to get a Locale which the Scanner class is using. Syntax Following is the declaration of locale() method: public Locale locale() Parameter This method does not accept any parameter. Returns The locale() method returns this scanner's locale. Exceptions NA Compatibility Version Java 1.5 and above Example 1 import java.util.*; public class...
2 min read
Java Scanner.Int() Method The Int() method in Java is part of the java.util.Scanner class that provides methods for parsing and reading various primitive types and strings. The Int() method of Java Scanner class is used to scan the token of the input as an int....
9 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India