Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Java Help plzz
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="highlander" data-source="post: 10701266" data-attributes="member: 222356"><p>4. in java, there are 'implicit' primitive types for each value type. when you declare a value like 35.5, compiler assumes that it is a double value - that's the implicit primitive data type used to store decimal values. </p><p></p><p>so here the problem is, float is a smaller data type than double (float = 32bits, double =64 bits), so it is not possible to represent all double values using floats, coz floats have a much less value range. </p><p>hence the compiler will give u an error. </p><p></p><p>imagine what will happen if the compiler doesn't give you an error.</p><p>you try to store a value like 1000000000000000000000000000000000.11 using a float. but since float is too small to keep such big values, only part of that will be stored. so if you run it, it will cause bugs at runtime.</p><p>you can still use casting if you want to forcibly store values.</p><p>eg: float x= (float)35.5; </p><p></p><p></p><p>8. like the previous one, in k = k*100, the jdk will take '100' as an int. coz its the implicit type used for non-decimal numbers.</p><p></p><p>so here we get two different data types to operate. k = short & 100 = int.</p><p>but machines can't do operations with two different data types. so here 'k' also gets automatically converted to an 'int'</p><p>so the answer of k*100 is int.</p><p></p><p>but 'k' is short, and it is smaller than int. a similar problem like in Q4 can occur. hence, this gives an error.</p><p>if you want to correct it, you can again cast it forcibly:</p><p>k = (short)(k*100)</p></blockquote><p></p>
[QUOTE="highlander, post: 10701266, member: 222356"] 4. in java, there are 'implicit' primitive types for each value type. when you declare a value like 35.5, compiler assumes that it is a double value - that's the implicit primitive data type used to store decimal values. so here the problem is, float is a smaller data type than double (float = 32bits, double =64 bits), so it is not possible to represent all double values using floats, coz floats have a much less value range. hence the compiler will give u an error. imagine what will happen if the compiler doesn't give you an error. you try to store a value like 1000000000000000000000000000000000.11 using a float. but since float is too small to keep such big values, only part of that will be stored. so if you run it, it will cause bugs at runtime. you can still use casting if you want to forcibly store values. eg: float x= (float)35.5; 8. like the previous one, in k = k*100, the jdk will take '100' as an int. coz its the implicit type used for non-decimal numbers. so here we get two different data types to operate. k = short & 100 = int. but machines can't do operations with two different data types. so here 'k' also gets automatically converted to an 'int' so the answer of k*100 is int. but 'k' is short, and it is smaller than int. a similar problem like in Q4 can occur. hence, this gives an error. if you want to correct it, you can again cast it forcibly: k = (short)(k*100) [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom