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

Ls 7 - Conditional and Looping Statements - Worksheet 3

Uploaded by

Mandadi Jyoshna
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)
17 views

Ls 7 - Conditional and Looping Statements - Worksheet 3

Uploaded by

Mandadi Jyoshna
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/ 3

Ls -6 Conditional and looping statements

Worksheet 3
1) Give the output of the following program segment and
also mention how many times the loop is executed:
int a;
for(a=6; a>10; a++)
System.out.println(a*5);

2) Convert the following for loop into do while loop:


int a=5;
int i;
for(i=1; i<=10; i++)
{
a= a*3;
System.out.println(a);
}
3) Convert the following if-else-if construct into switch case:
if (res ==1)
System.out.println(“Pass”);
else if(res ==2)
System.out.println(“Good performance”);
else if(res ==3)
System.out.println(“best”);
else
System.out.println(“you need improvement”);

4) Consider the following program:


public class Test
{
void main( )
{
int i=0;
for( i=0; i<10; i++)
{
break;
}
System.out.println(i);
(a) What will be the output of the above code?
(b) How many times the for loop will execute?

5) Analyze the following program segment and answer the


following questions:
for(i=3; i<=4; i++)
{
for(j=2; j<i; j++)
{
System.out.print(“*”);
}
System.out.println(“Simply”);
}
(a) How many times in total will the inner loop execute?
(b) Write the output of the program segment.

6) Give the output of the following code segment.


switch(opn)
{
case ‘a’ : System.out.println(“Platform
Independent”);
break;
case ‘b’ : System.out.println(“Object Oriented”);
case ‘c’ : System.out.println(“Robust”);
break;
default : System.out.println(“Wrong Input”);
}

7) The following program is supposed to print the following


pattern. There are some places in the code marked by ?
1?, ?2?, ?3?, which must be replaced by an expression/ a
statement so that the function works correctly.
5
45
345
2345
12345
class Question
{
public static void main( )
{
for(int i=5; ?1?; i--)
{
for(?2?; ?3?; j++)
System.out.printl(j);
}
}
}

8) Write the output:

for (int i=10; i<=20; i=i+2)


{
System.out.println( i- -);
}

9) Write the output:


System.out.println(Math.abs(-
12.34)+Math.sqrt(625));
System.out.println(Math.ceil(-2.3)+Math.floor(-5.6));

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