0% found this document useful (0 votes)
39 views

Loops: Final Int MIN 10, MAX 20 Int Num 15

The document provides 15 exercises involving loops in Java. Each exercise prints output based on initializing an integer variable num to 15 and declaring constants MIN=10 and MAX=20. The exercises demonstrate while, do-while, and for loops, printing numbers, even/odd checks, nested loops, and arithmetic operations.

Uploaded by

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

Loops: Final Int MIN 10, MAX 20 Int Num 15

The document provides 15 exercises involving loops in Java. Each exercise prints output based on initializing an integer variable num to 15 and declaring constants MIN=10 and MAX=20. The exercises demonstrate while, do-while, and for loops, printing numbers, even/odd checks, nested loops, and arithmetic operations.

Uploaded by

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

Exercise Worksheet Java Software Solutions

Loops
For exercises 1 to 15, indicate the output that will be produced. Assume the following declarations are made
just before each exercise. That is, assume these initializations are in effect at the beginning of each problem:

final int MIN = 10, MAX = 20; int num = 15;


1. while (num < MAX)
{
System.out.println (num); num = num + 1; }
2. while (num < MAX)
{
num = num + 1; System.out.println (num); }

3. do
{
num = num + 1; System.out.println (num); }
while (num <= MAX);
4. while (num < MAX)
{
System.out.println (num); num = num - 1; }
5. while (num > MIN)
{
System.out.println (num); num = num - 1; }
6. while (num < MAX)
{
System.out.println (num); num += 2; }

7. while (num < MAX)


{
if (num%2 == 0) System.out.println (num); num++; }
8. do
{
num = num + 1;
if (num*2 > MAX+num) System.out.println (num); }
while (num <= MAX);
9. for (int value=0; value >= 7; value++)
System.out.println (value);
10. for (int value=7; value < 0; value--)
System.out.println (value);
11. for (int value=1; value <= 20; value+=4)
System.out.println (value);
12. for (int value=num; value <= MAX; value++)
System.out.println (value);
13. for (int value=num; value <= MAX; value++)
if (value%4 != 0)
System.out.println (value);
14. for (int count1=1; count1 <= 7;count1++)
{
for (int count2=1; count2 <=5; count2++)
System.out.print ("#");
System.out.println();
}

15. for (int count1=1; count1 <= 5; count1++)


{
for (int count2=1; count2 <= 5; count2++) System.out.print (count1*count2 + " ");
System.out.println();

You might also like