CrazyEngineers
  • Problem in java program

    anksingla

    anksingla

    @anksingla-ttYJbX
    Updated: Oct 14, 2024
    Views: 1.4K
    byte b=10 shows no error but
    float f =10.0 shows error that double found..

    why??
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • radha gogia

    MemberSep 4, 2014

    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
    Are you sure? This action cannot be undone.
    Cancel
  • anksingla

    MemberSep 4, 2014

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register