Page 342 - Computer science 868 Class 12
P. 342
{
System.out.print(arr[j][i]+"\t");
}
System.out.println();
}
}
public void display()
{
System.out.println("ORIGINAL ARRAY");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
transpose();
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size");
int mm=sc.nextInt();
Trans obj=new Trans(mm);
obj.fillarray();
obj.display();
}
}
3. With reference to the following program code, answer the questions that follow:
void test(int arr[])
{ int c=0,s=0;
for(int i=0;i<arr.length; i++)
{ for(int j=1;j<=arr[i];j++)
{if(arr[i]%j==0) c++;}
if(c==2) s++;c=O;
}
System.out.println(s);
}
(i) What will be the output of the method test() when the value of arr[]={2,9,13,18,21,29}? [ISC 2022]
(a) 3 (b) 4
(c) 0 (d) 1
Ans. (a)
(ii) What is the method test() performing? [ISC 2022]
(a) Counting the odd numbers (b) Checking for the maximum element
(c) Checking the perfect numbers (d) Counting the prime numbers
Ans. (d)
4. The following program code converts a decimal integer number ‘num’ to its equivalent value in any given base ‘b’ . There are
some places in the code marked as ?1?, ?2?, ?3?, ?4? and ?5? which are to be replaced by a statement/expression so that the
code works properly.
void convertnum(int num, int b)
{ int A[]=new int[20];
int x=?1 ?;
while(num !=0 )
{ A[x++]=?2?;
num /=b;
}
for(int i=?3?;i>=0;i--)
{ if( ?4?)
System.out.print(A[i]);
340340 Touchpad Computer Science-XII

