Sunday, January 12, 2014

Java Data Types Programming Examples

//Note:  Analysis the programs errors,outputs and Understand the Java Data Type concepts

//[1]
class Demo1{
public static void main(String arg[]){
byte b=278;
System.out.println("b="+b);
}
}

//[2]
class Demo2{
public static void main(String arg[]){
byte b=78;
short s=178;
long i=20;
int k=b+i+s;
System.out.println("k="+k);
}
}

//[3]
class Demo3{
public static void main(String arg[]){
byte b1=78;
byte b2=78;
byte b3=b1+b2;
System.out.println("b3="+b3);
}
}

//[4]
class Demo4{
public static void main(String arg[]){
float f=78.8f;
float d=78.9+f;
System.out.println("d="+d);
}
}

//[5]
class Demo5{
public static void main(String arg[]){
char c='a';
System.out.println("c="+c);
int i=c+1;
System.out.println("i="+i);
System.out.println("c="+(char)i);
}
}

//[6]
class Demo6{
public static void main(String arg[]){
short s=12;
int i=s;
float f=s;
System.out.println("s="+s);
System.out.println("i="+i);
System.out.println("f="+f);
}
}

//[7]
class Demo7{
public static void main(String arg[]){

char s='a';
int i=s;
float f=s;
System.out.println("s="+s);
System.out.println("i="+i);
System.out.println("f="+f);
}
}

//[8]
class Demo8{
public static void main(String arg[]){
short s;
int i=700;
s=(short)i;//convert integer to short

System.out.println("s="+s);
}
}

//[9]
class Demo9{
public static void main(String arg[]){
boolean b=true;
int i =(int)b;//incompatable
System.out.println("i="+i);
}
}

//[10]
class Demo10{
public static void main(String arg[]){
int i=10;
int j=3;
int k=i%j;
System.out.println("k="+k);
int a=i/j;
System.out.println("a="+a);

}
}

//[11]
class Demo11{
public static void main(String arg[]){
int i=10;
int j=3;
boolean b=(i==j);
System.out.println("b="+b);
}
}

//[12]
class Demo12{
public static void main(String arg[]){
int i=10;
int j=3;
int k=7;
boolean b=(i>j)^(i>k)^(i<j);
System.out.println("b="+b);
}
}

//[13]
class Demo13{
public static void main(String arg[]){
int i=10;
int j=3;
int k=7;
boolean b=((i>j)|(i>k))&(i<j);
System.out.println("b="+b);
}
}

//[14]
class Demo14{
public static void main(String arg[]){
int i=7;
int j=9;
int k=i&j;
System.out.println("k="+k);
}
}

//[15]
class Demo15{
public static void main(String arg[]){
int i=7;
int j=9;
int k=i^j;
System.out.println("k="+k);
}
}

//[16]
class Demo16{
public static void main(String arg[]){
int i=-8;
int j=~i;
System.out.println("j="+j);
}
}

//[17]
class Demo17{
public static void main(String arg[]){
int i=8;
int j=i<<2;
System.out.println("j="+j);
}
}

//[18]
class Demo18{
public static void main(String arg[]){
int i=0xf;//hex value stored
int j = 07;//octal value stored
char c ='a';
int k = i+j+c;//15+7+97
System.out.println(" c ="+c);
System.out.println(" unicode value of c ="+(int)c);
System.out.println(" k ="+i);
System.out.println(" k ="+j);
System.out.println(" k ="+k);
}
}


Post a Comment