My excuted programs

Saturday, June 30, 2007

Java Assignments Week 1 : Part 2 Q.11 - Q.14

Question 11


class mycontrolstr1 {
public static void main (String as []){
int x = 10 ;
while (x>=0){

System.out.println("Number =" + x);
}
}
}
Screen Shot


Question 12
class myfor {
public static void main (String as []){
int x = 10 ;
do {
System.out.println("Inside the loop" + x);
x--;
}while (x>=0);
}
}
Screen Shot


Question 13

class myname {
public static void main (String as []){

for (int x = 0; x<2;x++)> System.out.println("loop"+ x); }
}
}
Screen Shot



Question 14 :SCJP past question
class myname1 {
public static void main (String ar[]){

for (int x=0; x<2;x++){
for(int y = 0; y<3;>
if (x==y){

break ; ]
}
System.out.println("x = "+x +"y ="+y);
}

}
}
}



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

Prelude

I will using this blog to display the coding assignments I 've worked on .. sorry for the delay in posting but I had to shift to this blogging engine coz my previous one the url something went wrong. I'll be displaying the coding in text boxes and the relevant screen shot below it.