2020
The following function check () is a part of some class. What will the function check () return
when the value of?
(i) N=25
(ii) N=10
Show the dry run/working.
static int check (int n)
{
if(n<=1)
return 1;
if(n%2==0)
return 1 + check(n/2);
else
return 1 + check(n/2+1);
}
public static void main (String args[])
{
[Link](check(25));
[Link](check(10));
}
2019
The following function Mystery () is a part of some class. What will the function Mystery ()
return when the value of num=43629, x=3 and y=4 respectively? Show the dry run/working.
static int Mystery (int num, int x, int y)
{
if(num<10)
return num;
else
{
int z = num % 10;
if(z%2 == 0)
return z*x + Mystery (num/10, x, y);
else
return z*y + Mystery(num/10, x, y);
}
}
public static void main(String args[])
{
[Link](Mystery(43629,3,4));
}
2017
The following function magicfun () is a part of some class. What will the function magicfun ()
return, when the value of n=7 and n=10, respectively? Show the dry run/working: [5]
static int magicfun (int n)
{
if(n == 0)
return 0;
else
return magicfun(n/2) * 10 + (n%2);
}
public static void main(String args[])
{
[Link](magicfun());
}
2016
The following function Check () is a part of some class. What will the function Check () return
when the values of both ‘m’ and ‘n’ is equal to 5? Show the dry run/working. [5]
static int Check (int m, int n)
{
if(n == 1)
return -m--;
else
return ++m+Check (m, --n);
}
public static void main(String args[])
{
[Link](Check(5,5));
}
2015
The following function is a part of some class. Assume ‘x’ and ‘y’ are positive
integers, greater than 0. Answer the given questions along with dry run / working.
static void someFun (int x, int y)
{
if(x>1)
{
if(x%y==0)
{
[Link](y+" ");
someFun(x/y, y);
}
else
someFun(x, y+1);
}
}
public static void main(String args[])
{
someFun(24,2);
}
(i) What will be returned by someFun (24,2)?
(ii) What will be returned by someFun (84,2)?
(iii) State in one line what does the function someFun () do, apart from recursion?
2014
The following functions are part of some class
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”?
iii) State in one line what does the function fun1() do apart from recursion
static void fun1(char s[], int x)
{
[Link](s);
char temp;
if(x<[Link]/2)
{
temp=s[x];
s[x] = s[[Link]-x-1];
s[[Link]-x-1]=temp;
fun1(s, x+1);
}
}
static void fun2(String n)
{
char c[]=new char[[Link]()];
for(int i=0;i<[Link]; i++)
c[i]=[Link](i);
fun1(c,0);
}
public static void main(String args[])
{
char c[]={'J','U','N','E'};
fun1(c,1);
fun2("SCROLL");
}
2013
The following function Recur is a part of some class. What will be the output of the function
Recur () when the value of n is equal to 10. Show the dry run / working. [5]
static void Recur (int n)
{
if (n>1)
{
[Link] (n + " " );
if(n%2 !=0)
{
n = 3* n + 1;
[Link](n + " ");
}
Recur (n/2);
}
}
public static void main(String args[])
{
Recur(10);
}
2012
The following function witty() is a part of some class. What will be the output of the function
witty( ) when the value of n is ‘SCIENCE’ and the value of p is 5. Show the dry run/working:
static void witty ( String n, int p)
{
if (p<0)
[Link](" ");
else
{
[Link]( [Link](p) + ".");
witty(n,p-1);
[Link]([Link](p));
}
}
public static void main(String args[])
{
witty("SCIENCE",5);
}
2011
The following is a part of some class. What will be the output of the function mymethod()
when the value of the counter is equal to 3? Show the dry run/working. [5]
static void mymethod (int counter)
{
if (counter == 0)
[Link]. println (" ");
else
{
[Link] ("Hello" +counter);
mymethod (--counter);
[Link] (" " +counter);
}
}
public static void main(String args[])
{
mymethod(3);
}
2010
The following functions numbers (int) and numbers1 (int) are a part of some class. Answer
the questions given below showing the dry run/working:
static void numbers (int n)
{
if (n > 0)
{
[Link]. print(n + " " );
numbers (n-2);
[Link](n + " ");
}
}
static String numbers1 (int n)
{
if (n <= 0)
return " ";
return numbers1(n-1) + n + " ";
}
public static void main(String args[])
{
numbers(5);
[Link]();
[Link](numbers1(6));
}
(i) What will be the output of the function numbers (int n) when n = 5?
(ii) What will the function numbers1 (int n) return when n = 6?
2009
The following function trial () & perform () are a part of some class. Answer the following
parts given below. Show the dry run/working.
static int trial(int n)
{
if(n==1)
return 2;
else if (n==2)
return 3;
else
return trial(n-2)+trial(n-1);
}
static void perform(int p)
{
int x;
for(int i=1;i<=p;i++)
{
x=trial(i);
[Link](x+" ");
}
}
public static void main(String args[])
{
[Link](trial(4));
perform(5);
}
(i) what will the function trial () return when the value of n is 4?
(ii) what will the function perform () return when the value of p is 5?
(iii) In one-line state what the function trial () is doing, apart from recursion?
2008
The following function show() & calling are a part of some class. Assume that the parameter
n is greater than 1 when the function is invoked. It returns the value 1 when true otherwise
it returns 0.
Show the dry run/working.
static void calling(int i)
{
int f=2;
int n=0;
show(n,f);
}
static int show(int n, int f)
{
if(n==f)
return 1;
if(n%f==0||n==1)
return 0;
else
return show(n,f+1);
}
public static void main(String args[])
{
[Link](show(27,2));
}
(i) what will the function show() return when the value of n is 11?
(ii) what will the function show() return when the value of n is 27?
(iii) in one line state what the function show() is doing, apart from recursion?
2007
In the following, function strange is a part of some class. Assume that argument x & y are
greater than 0 when the function is invoked. Show the dry run/working.
static int stranger(int x, int y)
{
// assuming x>=0 & y>0
if(x>=y)
{
x=x-y;
return stranger(x, y);
}
else
{
return x;
}
}
public static void main(String args[])
{
[Link](stranger(20,5));
[Link](stranger(15,6));
}
(i) What will function strange (20,5) return?
(ii) What will function strange (15,6) return?
(iii) In one-line state, what the function strange(..) is doing?
The following function find( ) and perform( ) are a part of some class. Show the dry run/working.
static int find(int n, int p)
{
if(n == 0)
return p;
else
return find(p%n,n);
}
static void perform(int m)
{
int q = 14;;
int x = find(q++, ++m);
[Link](x);
}
public static void main(String args[])
{
[Link](find(12,8));
perform(20);
}
(i) What will the function find(12,8) return?
(ii) What will be the output of the function perform( ) when the value of m is 20?
(iii) In one line state what the function find( ) is doing, apart from recursion.