Page 427 - Cs_withBlue_J_C11_Flipbook
P. 427
{
System.out.println(c. …………………);
d. …………………
}
else
e. …………………
}
2. Fill in the blanks to return the LCM of two numbers a and b using the recursive method int lcm(int a, int b, int lc) where a=24,
b=36 and lc=1.
void lcm(int a, int b, int lc)
{
if(a. …………………)
b. …………………
else
{
c. …………………
}
}
3. Fill in the blanks to find the frequency of the vowels in a String using recursive method int count(String s, int p) where s=“UKRAINE”
and p=s.length()-1.
int count(String s, int p)
{
if(a. …………………)
b. …………………
else if(c. …………………)
return 1+ e. …………………
else
e. …………………
}
C. Answer the following questions:
1. The following function is a part of some class. Predict the output of the methods with proper working/dry run. [ISC 2014]
void fun1char s[ ],int x)
{
System.out.println(s);
char temp;
if(x<s.length/2)
{
temp=s[x];
s[x]=s[s.length-x-1];
s[s.length-x-1 ]=temp;
fun1(s, x+1);
}
}
void fun2(String n)
{
char c[ ]=new char[n.length()];
for(int i=0;i<c.length; i++)
c[i]=n.charAt(i);
fun1(c,0);
}
425
Recursion 425

