0% found this document useful (0 votes)
11 views11 pages

Inft231101081 Oop Lab 4

This document discusses loops in Java. It includes questions about calculating power using loops, printing numbers in a specific format using loops, nested loops to print patterns, and user input validation using loops. It also asks questions to test the understanding of different loop types like do-while and while loops.

Uploaded by

Muhammad Haziq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Inft231101081 Oop Lab 4

This document discusses loops in Java. It includes questions about calculating power using loops, printing numbers in a specific format using loops, nested loops to print patterns, and user input validation using loops. It also asks questions to test the understanding of different loop types like do-while and while loops.

Uploaded by

Muhammad Haziq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

JAVA LOOPS

Lab-04

Submitted by: Abdul Samad.


Submitted to: Ms Kiran Yaqoob
Roll no: Inft231101081.

LAB 04 Loops in Java

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.

Question 2: Implement question 1 using while loop.

Question 3: Write a program called CozaLozaWoza which prints the numbers


1 to 110, 11 numbers per line. The program shall print "Coza" in place of the
numbers which are multiples of 3, "Loza" for multiples of 5, "Woza" for
multiples of 7, "CozaLoza" for multiples of 3 and 5, and so on. The output shall
look like:

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:

Question 1: What is the difference between do while and while loop?


Question 2: What will be the output of the following program?

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

You might also like