Monday, 28 September 2015

Demo on for,while and do..while loops


public class First {
public static void main(String args[]){
int i,j=0,k=0;
for(i=0;i<=10;i++){
System.out.println("The value of i is " +i +"\n");
}
while(j<=10){
System.out.println("The value of J is " +j +"\n");
j++;
}
do{
System.out.println("The value of k is " +k +"\n");
k++;
}while(k<=10);
}
}


Output:-
The value of i is 0

The value of i is 1

The value of i is 2

The value of i is 3

The value of i is 4

The value of i is 5

The value of i is 6

The value of i is 7

The value of i is 8

The value of i is 9

The value of i is 10

The value of J is 0

The value of J is 1

The value of J is 2

The value of J is 3

The value of J is 4

The value of J is 5

The value of J is 6

The value of J is 7

The value of J is 8

The value of J is 9

The value of J is 10

The value of k is 0

The value of k is 1

The value of k is 2

The value of k is 3

The value of k is 4

The value of k is 5

The value of k is 6

The value of k is 7

The value of k is 8

The value of k is 9

The value of k is 10

No comments:

Post a Comment