0
Can anyone explain my error
11 Respuestas
+ 2
You cannot store integer type in byte.
You need type casting to do so and also the number should be within the limit of byte data type.
A byte variable is 1 byte or 8 bits and it is an unsigned type, it can store -128 to 127.
You are trying to store a number larger than the limit of byte.
USE MAIN METHOD
+ 2
Ira Sarkar
public class Convert{
public static void main(String[] args) {
int i = 127;
byte b = (byte)i;
System.out.println ("value of byte variable =" + b);
}
}
+ 2
Do not ever feel embarrassed to share your problems. All of us were beginners at some point so do not hesitate to ask your doubts. It's completely normal.
This is how you will learn and remember if you see something similar next time.
+ 1
I started programming in practical last week
In this small programs, sometimes I'm facing problem. Embarrassment
Is this normal?
0
Yes, then what should I do
0
Thanks
0
Can I say one thing?
0
??
0
Thanks
0
Ira Sarkar Try it:
public class Convert
{
public static void main(String[] args) {
int i = 127;
byte b = (byte)(i);
System.out.println ("value of byte variable =" + b);
}
}
- Change the method to "main(String[] args);
- Change the int value to 127 (max that a byte can store);
- Change the sentence "byte b = i;" to "byte b = (byte)(i);".
0
Hi