Page 1 :
Wednesday, June 09, 2021, 8:06 PM, , COMBINED ISC 135 Page 1
Page 8 :
Question 3., (a) 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., void mymethod (int counter), {, if (counter == 0), System.out. println(” ");, else, {, System.out.println ("Hello" +counter);, mymethod (--counter);, System.out.println (" " +counter);, }, }, , ) 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:, class Trial1, {, public void witty(String n, int p), {, if(p<0), System.out.println(“”);, else, {, , COMBINED ISC 135 Page 8
Page 9 :
{, System.out.println(n.charAt(p)+”.”);, witty(n,p-1);, System.out.print(n.charAt(p));, }, }, }, , COMBINED ISC 135 Page 9
Page 11 :
Question 3., (a) The following functions are part of some class:, 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);, }, }, , (i) What will be the output of fun1() when, the value of s[ ]={‘J’,‘U’,‘N’,‘E’} and 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”?, (iii) State in one line what does the function fun1() do, apart from recursion. [1], , Question 3., (a) 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., void someFun(int x, int y), {, if(x>1), , COMBINED ISC 135 Page 11
Page 12 :
{, if(x%y == 0), {, System.out.print(y+ " ");, someFun(x/y, y);, }, else, someFun(x, y+1);, }, }, (i) What will be returned by someFun(24, 2)? [2], (ii) What will be returned by someFun(84, 2)? [2], (iii) State in one line what does the function someFun() do,, apart from recursion? [1], , 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], int Check (int m, int n), {, if(n = = 1), return -m --;, else, return + + m + Check (m, -- n);, }, , 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. [5], 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);, }, }, , The following function check() is a part of some class., What will the function check() return when the value of, (i) n = 25 and (ii) n = 10. Show the dry run/working., , int check(int n), {, if(n <= 1), return 1;, , COMBINED ISC 135 Page 12
Page 13 :
if(n % 2 == 0), return 1 + check(n / 2);, else, return 1 + check(n / 2 + 1);, }, 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], , int magicfun (int n), {, if(n = = 0), return 0;, else, return magicfun(n/2) * 10 + (n%2);, }, , COMBINED ISC 135 Page 13
Page 14 :
import java.util.*;, class linear, {, static int x[],size;, linear(int s), {, size=s;, x=new int[size];, }, void get(), {, Scanner sc=new Scanner(System.in);, System.out.println("Enter array elements");, for(int i=0;i<size;i++), x[i]=sc.nextInt();, }, int search(int low,int t), {, if(low<size), {, if(x[low]==t), return low;, else, return search(low+1,t);, }, else, , COMBINED ISC 135 Page 14
Page 15 :
return -1;, }, public static void main(), {, Scanner sc=new Scanner(System.in);, System.out.println("Enter size");, int sz=sc.nextInt();, linear obj=new linear(sz);, obj.get();, System.out.println("Enter target number");, int t=sc.nextInt();, int ch=obj.search(0,t);, if(ch==-1), System.out.println(t+" is not found");, else, System.out.println(t+" is found at index number "+ch);, }, }, , COMBINED ISC 135 Page 15