Saturday 17 March 2018

 Non - Primitive Datatypes



Wrapper Class 

👉 Program 1

class wrap
{
public static void main(String wrp[])
{
//primitive declaration
int p = 100;
System.out.println("primitive datatype = "  +p);

//non-primitive declaration
Integer h = new Integer(100);
System.out.println("non-primitive datatype = "  +h
);

Double d = new Double(2.1756);
System.out.println("non-primitive datatype = "  +d);

Character c = new Character('K');
System.out.println("non-primitive datatype = "  +c);

}


}

Output 


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: