Page 433 - Computer science 868 Class 12
P. 433
3. Fill in the blanks to find the frequency of vowel 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+ d.…………………
else
e.…………………
}
4. Fill in the blanks to produce the output 3 10 5 16 8 4 2 1 when method print(3) is executed
class Fillup{
void print(int n) {
System.out.print(n + " ");
if (a.…………………) {
if (b.…………………)
print(n / 2);
else
print(c.…………………);
}}}
C. Answer the following questions:
1. void fun 1 (char 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);
}
i. What will be the output of fun1( ) when the value of s[] = {‘J’,‘U’,‘N’,‘E’} and x = 1?
ii. What will be the output of fun2( ) when the value of n = ‘SCROLL”?
2. The following function is part of some class. What will be the method return if n = 29? Show working/dry run.
int generate(int x)
{
if(x<=2)
return x;
else
return generate(x/2)+generate(x/2+1);
}
3. The following function is part of some class. What will be the method print if n = 5? Show working/dry run.
void print(int n , int i, int j)
{ if(i>n)
System.out.println();
431
Recursion 431

