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

Revision_loops

The document contains a worksheet focused on analyzing loop execution and rewriting code snippets using different loop constructs. It includes multiple choice questions regarding loop outputs and tasks for rewriting loops in different formats. Additionally, it presents programming exercises related to user input and mathematical operations based on user choices.

Uploaded by

dssamana1011
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)
4 views

Revision_loops

The document contains a worksheet focused on analyzing loop execution and rewriting code snippets using different loop constructs. It includes multiple choice questions regarding loop outputs and tasks for rewriting loops in different formats. Additionally, it presents programming exercises related to user input and mathematical operations based on user choices.

Uploaded by

dssamana1011
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/ 3

Revision-Iteration statements

Worksheet-3
I. Analyze how many times the following loops gets executed and write
the output:
a)int x= 564;
for (; x>0; x/=10)
System.out.println (x%10);

b)int x=15;
while(x>5)
{
System.out.println(x++);
++x;
}

c) int m=2,n=15;
for(int i=1;i<5;i++)
{
m++;
--n;
}
System.out.println ("m="+m);
System.out.println ("n="+n);
d) int m;
for(m=10; m>0 & m<=30; m+=10);
System.out.println ("m="+m);

II.Rewrite as directed:-
a) Write using while loop
for (int a=10, b=20; a<=50; a+=5)
{
System.out.print(a);
System.out.println (b);
}

b)Write using for loop


int s=0,k=1;
while(k<=10)
{s=s+k;
k++;
}
System.out.println(“Result is”+s);

Programs:-
1) Accept your age and display your name no of times based on the
age.
2)Write a program to accept two numbers and perform the following
based on the user’s choice.
Choice 1:-To display the HCF of the numbers input by the user.
Choice 2:-To display count of common factors of the numbers input
by the user.
Display an appropriate message if the choice is not valid.

3)Write a program using a switch statement to perform the following


based on the user’s choice.
Choice 1:-To display first n negative odd numbers.
Choice 2:-To display Positive even numbers from n to 1.

***

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