Jump to content

need help with these questions

- - - - -

  • Please log in to reply
2 replies to this topic

#1
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
1. Why does Java provide both ints and floats, if floats can encode any possible int?


2. Why does Java provide four types for storing integer data (byte, short, int, and long)? I.e., why would you use one over another?

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Run this:
public static void main(String[] args) {
        System.out.println("float - max: " + Float.MAX_VALUE + " | min: " + Float.MIN_VALUE  + " | memory size: " + Float.SIZE +" bit");
        System.out.println("int - max: " + Integer.MAX_VALUE + " | min: " + Integer.MIN_VALUE + " | memory size: " + Integer.SIZE +" bit");
        System.out.println("double - max: " + Double.MAX_VALUE + " | min: " + Double.MIN_VALUE  + " | memory size: " + Double.SIZE +" bit");
        System.out.println("short - max: " + Short.MAX_VALUE + " | min: " + Short.MIN_VALUE + " | memory size: " + Short.SIZE +" bit");
        System.out.println("double - max: " + Long.MAX_VALUE + " | min: " + Long.MIN_VALUE  + " | memory size: " + Long.SIZE +" bit");
        System.out.println("byte - max: " + Byte.MAX_VALUE + " | min: " + Byte.MIN_VALUE + " | memory size: " + Byte.SIZE +" bit");
}
Various types can store values that would be too big for others.
Also memory usage may be a reason to take one type over another.

#3
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
Thanks lot wim DC.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users