My excuted programs

Saturday, June 30, 2007

Assignment week1:Part1 Q.4 - Q.10


Question 04
class MyCast {

public static void main (String ar[]){

byte b = 50 ;
short s = b ;

float f = 10.0F;
double d = f ;

int i = 100 ;
//s = i ;
s = (short) i;
System.out.println("cast complete");


}
}
Screen shot




Question 05 Modulus Operator

class myoperator {
public static void main (String ard[]){
]
int a = 24 ; double b = 24.2;
System.out.println ("a%10 = "+a%10 );

System.out.println ("b%10 = "+b%10 );
}
}
Screen Shot

Question 06 Increment/ Decrement Operators

class myoperator1 {
public static void main (String as []){
int a =1;
System.out.println(a++);
System.out.println(a--);


}
}

Screen Shot


Question 07: Assignment Operations

class myop2 {
public static void main (String as []){
int a = 1;
a = a+10;
System.out.println(a);
a += 10;
System.out.println(a);

}
}

Screen Shot


Question 08: Relational Operators

class myop3 {
public static void main (String as []){
int a = 4;
if (a==4){
System.out.println("Value of a is 4");

}else if (a!=4){

System.out.println("Value of a is not 4");

} else if (a<4){ System.out.println("Value of a is 4");

}else System.out.println("another relation");
}
}

Screen Shot



Question 10:Case statements
class mycontrolstr {
public static void main (String as []){
switch (2){
case 1:
System.out.println("case1");
break;
case 2:
System.out.println("case1");
break;
default:
System.out.println("case1");

}

}
}

Screen shot

No comments: