9th Dec 2019, 5:22 AM
Ira Sarkar
Ira Sarkar - avatar
11 Answers
+ 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
9th Dec 2019, 5:25 AM
Avinesh
Avinesh - avatar
+ 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); } }
9th Dec 2019, 5:32 AM
Avinesh
Avinesh - avatar
+ 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.
9th Dec 2019, 5:52 AM
Avinesh
Avinesh - avatar
+ 1
I started programming in practical last week In this small programs, sometimes I'm facing problem. Embarrassment Is this normal?
9th Dec 2019, 5:49 AM
Ira Sarkar
Ira Sarkar - avatar
0
Yes, then what should I do
9th Dec 2019, 5:27 AM
Ira Sarkar
Ira Sarkar - avatar
0
Thanks
9th Dec 2019, 5:36 AM
Ira Sarkar
Ira Sarkar - avatar
0
Can I say one thing?
9th Dec 2019, 5:36 AM
Ira Sarkar
Ira Sarkar - avatar
0
??
9th Dec 2019, 5:37 AM
Avinesh
Avinesh - avatar
0
Thanks
9th Dec 2019, 5:56 AM
Ira Sarkar
Ira Sarkar - avatar
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);".
10th Dec 2019, 11:30 PM
Eduardo Cavalcante
Eduardo Cavalcante - avatar
0
Hi
11th Dec 2019, 4:56 AM
Weaogh Deaf
Weaogh Deaf - avatar