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, {, System.out.println(n.charAt(p)+”.”);, witty(n,p-1);, System.out.print(n.charAt(p));, }, }, }, , COMBINED ISC 135 Page 8
Page 10 :
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;, , (i) What will be the output of fun1() when, the value of s[ ]={‘J’,‘U’,‘N’,‘E’} and x = 1?, , COMBINED ISC 135 Page 10
Page 11 :
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”?, (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), {, 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, , COMBINED ISC 135 Page 11
Page 12 :
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;, 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 12
Page 13 :
import java.util.*;, class linear, {, static int x[],size;, , COMBINED ISC 135 Page 13
Page 14 :
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, 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 14
Page 15 :
A class Admission contains the admission numbers of 100 students. Some of the data members/member, functions are given below:, Class name, , : Admission, , Data member/instance variable:, Adno[], : integer array to store admission numbers, Member functions/methods:, Admission(), : constructor to initialize the array elements, void fillArray() : to accept the elements of the array in, ascending order, , int binSearch(int l, int u, int v): to search for a particular admission number (v) using binary search and recursive, , COMBINED ISC 135 Page 15
Page 16 :
technique and returns 1 if found otherwise returns -1, , Specify the class Admission giving details of the constructor, void fillArray() and int binSearch(int, int, int). Define, the main() function to create an object and call the functions accordingly to enable the task., , import java.util.*;, class Admission, {, int Adno[]=new int[5];, Admission(), {, for(int i=0;i<5;i++), Adno[i]=0;, }, void fillarray(), {, Scanner sc=new Scanner(System.in);, System.out.println("Enter array elements in ascending order");, for(int i=0;i<5;i++), Adno[i]=sc.nextInt();, }, int binsearch(int l,int u,int v), {, if(l<=u), {, int m=(l+u)/2;, if(v>Adno[m]), return binsearch(m+1,u,v) ;, else if(v<Adno[m]), return binsearch(l,m-1,v) ;, else, return 1;, }, else, return -1;, }, public static void main(), {, Admission obj=new Admission();, Scanner sc=new Scanner(System.in);, obj.fillarray();, System.out.println("Enter target number");, int t=sc.nextInt();, int ch=obj.binsearch(0,4,t);, if(ch==-1), System.out.println(t+" is not found");, else, System.out.println(t+" is found");, }, }, , COMBINED ISC 135 Page 16