0% found this document useful (0 votes)
30 views3 pages

Ls 7 - Conditional and Looping Statements - Worksheet 1

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)
30 views3 pages

Ls 7 - Conditional and Looping Statements - Worksheet 1

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 1

Question 1
Choose the correct answer and write the correct option:
1) Which of these selection statements test only for equality?
a) if
b) switch
c) if & switch
d) none of the mentioned

2) In the while and do-while loops, a ………………… statement


causes control to be transferred directly to the conditional
expression that controls the loop.
a) break
b) pause
c) start
d) continue
3) Which Java package includes the Math class?

a) java.io
b) java.lang
c)java.util
d) java.sys

4) What will be the output of Math.pow(2, 0)?

a) 0.0
b) 1.0
c)2.0
d) -1.0

5) What is the value of “d” in the following Java code


snippet?
double d = Math.round ( 2.5 + Math.random( ) );
a) 2
b) 3
c) 4
d) 2.5

6) What is printed as a result of the following code


segment?
for(int k=0; k<20; k+=2){
if(k%3 == 1)
System.out.print(k + “ ”);
}
a) 0 2 4 6 8 10 12 14 16 18
b) 4 16
c) 0 6 12 18
d) 4 10 16

7)What will be the output of following program?


public class temp
{
public static void main()
{
for(int i=1; i<=10; i++);
System.out.print(i);
}
}

a)12345678910
b) 11
c)Error
d) 1 2 3 4 5 6 7 8 9 10

8) How many times the following loop will get executed?

int counter=1;
do
{
System.out.println(counter);
}
while(counter++ < 5);

a)3
b) 4
c)5
d) 6

9) What will be the output of the following code snippet?


int a=15;
int b=25;
if((a<b) || (a=5)>15)
System.out.println(a);
else
System.out.println(b);
a) Error
b) 15
c) 25
d) No output

10) Assertion: do – while loop is known as exit-controlled


loop.
Reason: This loop ensures that the complete loop is
executed at least
once, then it checks whether the given condition is true or
false.
a)Both Assertion and Reason are true. Reason is the
correct explanation of Assertion
b) Both Assertion and Reason are true. Assertion is the
correct explanation of Reason
c)Assertion is true and Reason is false
d) Assertion is false and reason is true

11) The break statement in java is used to:


a) Terminates from the loop immediately
b) Terminates from the program immediately
c) Skips the current iteration
d) All of these

12) What will be the output of the following code snippet?


int count =1;
while(count<=15)
System.out.println(count%2 == 1 ? “A” : “B”);
++ count;

a) 15 times A will be printed


b) 15 times B will be printed
c) 8 times A and 7 times B
d) Both will print only once

You might also like