Java Scanner nextByte() Method

The next byte method

If we are required to get the user input in form of a byte, we can make use of the next byte method here. So, below is the implementation of the next byte method, where we are trying to get a byte as input from the user.

Java Scanner nextByte() method example

Here is the implementation →

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
byte storesbyte = scanner.nextByte();
System.out.println(storesbyte);
}
}

In the above method, the user can enter a byte type data, which lies in the range from -128 to 127. If the user input lies in this range, everything is fine. But if we move out of this range, then it throws an error as the value is out of range.