[Go to site: main page, start]

0% found this document useful (0 votes)
6 views2 pages

Convert While Loop to For Loop in Java

The document provides a series of programming tasks including converting a while loop to a for loop, writing method prototypes, invoking methods, creating an OTP, and implementing classes for palindrome checking, vowel and consonant counting, and calculating LCM and GCD. It also mentions performing a selection sort on 10 numbers. Each task includes specific code snippets and explanations of their functionality.

Uploaded by

mitratathastu7
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)
6 views2 pages

Convert While Loop to For Loop in Java

The document provides a series of programming tasks including converting a while loop to a for loop, writing method prototypes, invoking methods, creating an OTP, and implementing classes for palindrome checking, vowel and consonant counting, and calculating LCM and GCD. It also mentions performing a selection sort on 10 numbers. Each task includes specific code snippets and explanations of their functionality.

Uploaded by

mitratathastu7
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

CONVERT THE FOLLOWING WHILE LOOP PROGRAM SEGMENT TO FOR LOOP

1. a=10; b=10; 2. a=15;


while(a<=20) while(a>=1)
{ [Link](a*b); { a--;
a++; }
} [Link](a*a);
Write the method prototype :
Method compute accepts an integer and returns
a character
Method to check whether the given number is
even or odd
How are the following methods are invoked ?
void print()
boolean check (int n)
int calculate (String s, int n)
The following code CREATES AN OTP WITH 6 DIGITS
void OTP()
{
[Link](__________________________);

//malayalam, mom, QUEEN (Write output and explain)


class palin
{
boolean palindrome(String s)
{
int i, l=[Link](),j;
for(i=0,j=l-1;i<l/2;i++,j--)
{
if([Link](i)!=[Link](j))
return false;
}
return true;
}
}

//to count vowels and consonants (Write output and explain)


class vowel
{ void count(String s)
{ int i, l=[Link](),v=0,c=0;char ch;
for(i=0;i<l;i++)
{ ch=[Link](i);
if([Link](ch))
{ if("AEIOUaeiou".indexOf(ch)>=0)
v++;
else
c++; } }
[Link]("Number of vowels = "+v);
[Link]("Number of Consonants="+c);
}
}

//to calculate the LCm and GCD(54,60)


class lcmgcd
{
void calc(int m, int n)
{
int k;
for(k = [Link](m, n); k % m != 0 || k % n != 0; k++);
[Link]("LCM = " + k);
for(k = [Link](m, n); m % k != 0 || n % k != 0; k--);
[Link]("GCD = " + k);
}
}

Do selection sort of 10 numbers.

You might also like