Inft231101081 Oop Lab 4
Inft231101081 Oop Lab 4
Lab-04
Lab Objectives:
1. Understand Java loops and their usage
2. Implement all types of loops
3. Understand practical usage of loops
Software Required:
JDK & Notepad/ Textpad
Question 1: The exponent tells you how many times to multiply the number by
itself. For instance, three to the power of four, or 3^4, will be: 3 x 3 x 3 x 3 = 9
x 9 = 81. Write a program for calculating power of a number using loop.
1 2 Coza 4 Loza Coza Woza 8 Coza Loza 11 Coza 13 Woza CozaLoza 16 17 Coza 19 Loza CozaWoza 22 23
Coza Loza 26 Coza Woza 29 CozaLoza 31 32 Coza ......
Question 4: Write a program which shows following output using nested loops
*
**
***
****
*****
******
Question 5: Ask user input to input values and check if value is multiple of 3. If
the given value is multiple of 3 then print “Yes! you reached end” otherwise
keep on looping and asking user to enter new number.
QUESTIONS
Please Fill the blank space with respective answers to following questions:
class ForSample
{
public static void main(String s[])
{
for(int i = 0; i <= 5; i++ )
{
System.out.println("i = " + i );
}
System.out.println("i after the loop = " + i );
}
}
Question 3: What will be the output of the following program?
class ForSample
{ public static void main(String
s[])
{ int i = 0;
for(;i <= 5; i++ )
{
System.out.println("i = " + i );
}
System.out.println("i after the loop = " + i );
}
Question 4: What will be output of following program. Explain your answer.
class Output
{ public static void main(String
s[])
{ int i = 1, j
= 10; do
{ if(i > j)
break; j--;
} while (++i < 5);
System.out.println("i = " + i + " and j = " + j);
}
}
Explain Here:
THE END