Sunday 11 March 2018



Variables and Datatypes


Write a program to print the values of a variables declared 
    using primitive datatypes:
üboolean
übyte
üshort
üint
ülong
üchar
üfloat
üdouble


Sol.   
 class datatype
{
public static void main(String data[])
{
//primitive datatypes
boolean a = false;
System.out.println("boolean is"+a+"by default");
//here + means concatenation

//byte datatype
byte b = 2;
System.out.println("byte is" +b);

//short datatype
short s = 20;
System.out.println("short is" +s);

//int datatype
int i = 200;
System.out.println("integer is" +i);

//long datatype
long l = 2000;
System.out.println("long is" +l);

//char datatype
char ch = 'A';
//char always declared in single quotes
System.out.println("char is" +ch);

//float datatype
float f = 2000000000f;
//0f means representing float numbers
System.out.println("float is" +f);

//double datatype
double d= 2000000000d;
//0d means representing double numbers
System.out.println("double is" +d);

}
}

Output:



No comments:

Post a Comment