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

While Do While Loop

The document contains multiple-choice questions (MCQs) and short answer questions related to while and do-while loops in programming. It also includes programming exercises focused on twisted prime numbers, palindrome checks, and number conversions. The questions aim to test understanding of loop constructs and number properties in Java.

Uploaded by

aanyachuriwal
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 views3 pages

While Do While Loop

The document contains multiple-choice questions (MCQs) and short answer questions related to while and do-while loops in programming. It also includes programming exercises focused on twisted prime numbers, palindrome checks, and number conversions. The questions aim to test understanding of loop constructs and number properties in Java.

Uploaded by

aanyachuriwal
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

Important Question for While and Do While Loop

MCQ1. Output of the given code:


int m=1000, k=3000;
while(++m < k--);
[Link](m);
a) 2000 b) 1999 c) 1998 d) 2001

MCQ2. How many times will the following loop execute:


int x = 12, y = 150;
do
{
++x;
y -= x++ + 1;
} while(x <= 25);
a) 5 b) 6 c) 8 d) 7

Short Questions
SQ1. State one similarity and one difference between while and for loop.
SQ2. Convert for loop to do..while loop.
int x=10, c=20;
do { [Link](c);
x++;
c=c-2;
} while(c>=10);
SQ3. Rewrite the following code using while loop:
int x=100;
for(int i=2;i<=22;i=i+4)
{ [Link]. print("\n"+(i+x));
x=x-2;
}
SQ4. How many times will the following loop get executed? What will be the
values of m and n after execution?
int ans =1, m=190, n=15, i=0;
while (m - n>=0)
{
ans = ans * 2;
m= m - n;
i++; }
SQ5. Convert the following code into for loop:
int h=10;
do {
h++;
[Link](h);
} while(h<=20);
SQ6. What will be the output of the program segment? How many times will
the loop be executed?
int k = 1, i = 2;
while(i < 12)
{ k += i;
i += 2;
}
[Link](k);
SQ7. Write the following program code using a for loop:
int a = 10, b = 20, x = 1, T;
while(x <= 4)
{ [Link](a);
a++;
x++;
}
[Link] the following for loop segment to an exit-controlled loop:
for(int p=25; p>=-25; p--)
{ [Link](p*3);
[Link](++p*2);
}

SQ9. State one similarity and one difference between entry control loop and
exit control loop.

SQ10. What will be the output of the following code and how many times the
loop will run?
int a = 1, b = 2;
while (++b < 16)
{
if (b % 3 == 0)
a *= b++;
b++;
}
[Link](a);

SQ11. Convert the following segment into an equivalent do...while loop.


int x, c;
for(x = 10, c = 20; c >= 10; c = c - 2)
{
[Link](c);
x++;
}

Important Programs
Prog 1. A twisted prime number is a prime number whose reverse is also prime.
Example: 73 → prime, reverse 37 → prime.
Write a program to print twisted prime numbers between N and M.
Prog 2. Write a program to input 10 numbers and check whether all entered
numbers are same. If yes, check whether the given number is a palindrome.

Prog 3. A palindromic prime number is a number which is palindrome as well


as prime.
Example: 141
Write a program to input a number and check whether the number is
palindromic prime number or not.

Prog 4. Write a Java program to input a three-digit number and rearrange its
digits to form a reverse number.

Prog 5. Write a program to find and print the largest palindrome made from the
product of two 3-digit numbers. Example 906609

Prog 6. A special two-digit number is a number such that sum of its digits +
product of its digits = original number.
Example: 59 → (5+9=14, 5×9=45, 14+45=59).
Write a program to print all two-digit special numbers.

Prog 7. Write a program to input 10 numbers and check whether all entered
numbers are same. If yes, check whether the given number is a palindrome.

Prog 8. Write a program to input a binary number and convert and print it in
equivalent decimal form.
For example: if input is 100110
then the decimal form of it is 38 as output.

Prog 9. Write a program to input a number and print the digits which occur
more than once in the given number. For example: if the input is 1233114,
Output will be: 1, 3

Prog 10. Write a program to convert a number to binary, octal or hexadecimal


depending upon user's choice.

You might also like