Problem in java program

byte b=10 shows no error but
float f =10.0 shows error that double found..

why??

Replies

  • radha gogia
    radha gogia
    anksingla
    byte b=10 shows no error but
    float f =10.0 shows error that double found..

    why??
    see in java by default each decimal value is taken as double so u need to explicitly mention it be ,say 5.98f becoz it wont take it otherwise float,it would take it to be double,similarly byte b=18;here 18 is int by default but its value lies in the range of byte numbers that is we can represent 18 in byte so i hope now u are clear
  • anksingla
    anksingla
    radha gogia
    see in java by default each decimal value is taken as double so u need to explicitly mention it be ,say 5.98f becoz it wont take it otherwise float,it would take it to be double,similarly byte b=18;here 18 is int by default but its value lies in the range of byte numbers that is we can represent 18 in byte so i hope now u are clear
    But if 10 is int then it should not be matters that value comes in range of byte or not. Since java does not type demotion.

You are reading an archived discussion.

Related Posts

In polymorphism we can create functions with same name. How memory is allocated to functions? Do same names means same memory? Basically I want to know what is happening in...
It seems that Microsoft Corp. did not stop after announcing the wonderful Lumia series- Lumia 830, Lumia 730 Dual SIM and Lumia 735 at IFA 2014. The tech giant has...
Motorola, previously owned by Google, soon to be in hands of Lenovo has announced the new generation of its smartphones. The closed door global launch event was held yesterday in...
Amidst all the announcements about amazing smartphones and accessories, we believe there's a tiny device - Moto Hint, that deserves your due attention. It is a wearable discreet wireless earbud...
https://timesofindia.indiatimes.com/...-Indias-top-IT-firms/articleshow/41535783.cms Why do you think? I think, IT firms mostly use Java or .NET and its difficulty to find quality programmers anyway.