Results 1 to 7 of 7
- 09-01-2008, 08:04 AM #1
- 09-01-2008, 08:09 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Change this as follows.
All variable lower that int are assign to int, unless you don't have specify.Java Code:byte c= (byte) (a + b);
Check the following code segment.
Java Code:byte a=10; byte b=5; int c=a+b; System.out.println(c);
- 09-01-2008, 08:15 AM #3
thank you sir
- 09-01-2008, 08:16 AM #4
- 09-01-2008, 08:49 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Conversion is happen automatically, if you are not specifically define.
byte and short variables are automatically convert into int, if you are not specifically define. See the example below.
In third line you are looking a short value, as c. But actually what you have found on right side is int value. Once you added two short value, compiler assign the value to an int, looking to add in 32 bits.Java Code:short a = 12; short b = 23; short c = a + b;
Same thing is happen for byte variables as well, I'll explain in the previous code.
On the other hand, float values also assign to double.
If you want to stuck with the same type, need explicit cast.
- 09-01-2008, 09:14 AM #6
- 09-01-2008, 09:23 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Connection Loss
By CrazyShells Slam in forum New To JavaReplies: 0Last Post: 05-15-2008, 02:56 PM -
error 530 error authentication required
By rgale in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-12-2008, 04:28 PM -
How do I convert a decimal value to hexadecimal with double precision (64 bit)
By SKaur in forum New To JavaReplies: 7Last Post: 01-12-2008, 09:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks