Monday, November 3, 2014

VARIABLES
There are two stages in a Variable.
1.       Declaring the variable.
2.       Initializing the variable.

Declaring the variable.
·         Introduce compiler about the variable type.
Initializing the variable.
·         Give a value to variable.
class Test{
          public static void main (String args []){
int x;                // Declaring the variable.
x=10;               // Initializing the variable.
System.out.println(x);
}
}



Ex 1:
java programme to print the value of x and y.

class Test{
            public static void main (String args []){
int x;
x=10;
int y =3;
System.out.println(“x = ”+ x+“, y = ”+y);
}
}
Ex 1:
java programme to print the sum of x and y.`



class Test{
            public static void main (String args []){
int x;
x=10;
int y =3;
System.out.println(“x = ”+ x+“, y = ”+y);
System.out.println(“Total = ”+ (x+y) );

}
}
Data types.
       
    
Primitive Data types.
byte
8 bits

Default data type for whole numbers.
short
16 bits
int
32 bits
long
64 bits
float
32 bits
Default data type for decimals.
double
64 bits
char
16 bits

boolean
bits

No comments:

Post a Comment