Friday, February 8, 2013

Week-2: 2.3: Variable : Float and Short

Two more variable types you can use are short and float. The short variable type is used to store
smaller number, and its range is between minus 32,768 and plus 32,767. Instead of using int in
our code on the previous pages, we could have used short instead. You should only use short if
you're sure that the values that you want to hold don't go above 32, 767 or below -32,768.

The double value we used can store really big numbers of the floating point variety. Instead of
using double, float can be used. When storing a value in a float variable, you need the letter "f"
at the end. Like this:

float first_number, second_number, answer;

first_number = 10.5f;
second_number = 20.8f;

for Details

1 comment:

  1. public static void main(String)[]args{
    first_number = 10.5;
    second_number = 20.5;
    answer = first_number/second_number;
    System.out .println("Total Answer = "+answer);