Data types in Java
Every variable in java has a data type. Data types specify the type and size of the value that can be stored.
Type |
Size |
Minimum Value |
Maximum Value |
Byte |
1 byte |
|
127 |
Short |
2 bytes |
|
32,767 |
Int |
4 bytes |
|
2,147,483,647 |
long |
8 bytes |
|
923,372,036,854,775,807 |
Size and Range of Integer Data types
Reading Data from Keyboard
readLine() is used to take input from the user in java .
import java.io.DataInputStream;
class reading
{
Public static void main ( String args[])
{
DataInputStream in = new DataInputStram(System.in);
Int intnumber = 0;
Float floatnumber = 0.0f:
Try
{
System.out.println(“Enter an Integer : “ );
Int number = Integer.parseInt(in.readLine());
System.out.println(“Enter a Float number “);
Floatnumber = Float.valueOf(in.readLine()).floatValue();
}
Catch( Exception e ){}
System.out.println(“ Integer number “ + intnumber);
System.ouyt.println(“ Float Value “ + floatNumber);
}
}
The intereactive input and output of the above program is as follows :
Enter and integer :
123
Enter a float number
123.45
Int number = 123
Floatnumber = 123.45