In this tutorial we will learn how to convert an int type value to byte type data.
This program will take an int value from console and provide a conversion to byte data. The line int myint = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and store in myint variable. The line byte mybyte = (byte)(myint); converts the myint int type value to mybyte byte type data.
import java.io.*;
class inttobyte {
public static void main(String[] args) {
try {
BufferedReader buffreader = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter the int value:");
int myint = Integer.parseInt(buffreader.readLine());
byte mybyte = (byte) (myint);
System.out.println("Convert value from int to byte is: " + mybyte);
} catch (Exception e) {
System.out.println(" Error " + e);
}
}
};

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.