0% found this document useful (0 votes)
2 views5 pages

Loopsassignments

The document contains a worksheet focused on Java loops, including output-based questions and loop interconversion exercises. It provides sample code snippets with expected outputs for various loop structures like while, for, and do-while loops. Additionally, it includes tasks requiring the conversion of loop types, demonstrating an understanding of loop functionality in Java.

Uploaded by

neelamvaram3
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)
2 views5 pages

Loopsassignments

The document contains a worksheet focused on Java loops, including output-based questions and loop interconversion exercises. It provides sample code snippets with expected outputs for various loop structures like while, for, and do-while loops. Additionally, it includes tasks requiring the conversion of loop types, demonstrating an understanding of loop functionality in Java.

Uploaded by

neelamvaram3
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/ 5

ICSE Java Worksheet: Loop Output & Interconversion (With Answers)

Section A: Output-Based Questions

Q1.

int i = 1, sum = 0;

while(i <= 3) {

sum += i;

System.out.print(sum + " ");

i++;

Answer: 1 3 6

Q2.

for(int i = 5; i >= 1; i--) {

if(i % 2 == 1)

System.out.print(i + " ");

Answer: 5 3 1

Q3.

int a = 2;

do {

System.out.print(a * a + " ");

a += 2;

} while(a <= 6);

Answer: 4 16 36
Q4.

for(int i = 1; i <= 4; i++) {

for(int j = 1; j <= i; j++) {

System.out.print(j);

System.out.println();

Answer:

12

123

1234

Q5.

int n = 1;

while(n <= 10) {

if(n % 3 == 0)

System.out.print(n + " ");

n++;

Answer: 3 6 9

Section B: Loop Interconversion

Q6. Convert to while loop:


for(int i = 10; i >= 1; i--) {

System.out.print(i + " ");

Answer:

int i = 10;

while(i >= 1) {

System.out.print(i + " ");

i--;

Q7. Convert to for loop:

int i = 2;

while(i <= 6) {

System.out.println(i);

i += 2;

Answer:

for(int i = 2; i <= 6; i += 2) {

System.out.println(i);

Q8. Convert to for loop:

int i = 1;

do {

System.out.print(i + " ");

i++;
} while(i <= 4);

Answer:

for(int i = 1; i <= 4; i++) {

System.out.print(i + " ");

Q9. Convert to do-while loop:

int i = 1;

while(i <= 3) {

System.out.println("Java");

i++;

Answer:

int i = 1;

do {

System.out.println("Java");

i++;

} while(i <= 3);

Q10. Convert to while loop:

for(char ch = 'A'; ch <= 'C'; ch++) {

System.out.print(ch + " ");

Answer:

char ch = 'A';

while(ch <= 'C') {


System.out.print(ch + " ");

ch++;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy