Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

COMPUTER APPLICATIONS 3rd PB CLASS X MM[50]

SECTION A [10 Marks]

SOLUTION AND
[ COMMON ERRORS ]

1. The following Access specifier allows access outside the class.

a) private b) protected c) public d) all the above

2. The pre condition of binary search is that the array


a) must be arranged in ascending order .
b) must be arranged in descending order
c) must be arranged in random order
d) must arranged in ascending or descending order

3. In the following code what type of variable is P:


class prog
{
int b;
void display()
{
int P=5;
}
}
a) global variable b ) local variable c) static variable d) instance variable

4. Automatic conversion of wrapper class to it’s corresponding primitive datatype is called

a) autoboxing b) unboxing c) type changing d) type conversion

5. Give output of the following code :


String s= “ACCESS”;
int ind =s.indexOf( ‘C’ ,2);
System.out.println(ind);
a) 1 b) 2 c) 3 d) 0

[ beg is included so 2 will be considered and C is at 2 ]


6. What is the return type of equalsIgnoreCase()
a) int b) boolean c) String d) char

7. String b []={ “ yes” ,” FALSE”, “true”. “NO”};


System.out.print ( b.length +” “+ b[1].length());
a) 4 5 b) 9 c) 45 d) 4 “ “ 5
8. Which of the following operators is used to allocate memory to the array variable in jave
A) alloc b) memory c) memalloc d) new

9. Library classes are


a) set of pre-defined classes b) set of used classes c)set of user classes d) none of the above

10. Give the output of the following String functions:


System.out.print( ANACONDA.replace(‘A’,’E’));
a) ENECONDE B) ENACONDA C) ANECONDE D) NONE OF THE ABOVE

[ WHILE PRINTING “ “ MISSING IN ANACONDA SO ERROR … THUS NONE OF THE ABOVE ]

Q 1.
import java.util.*;

class dig
{
public static void main()
{ Scanner sc= new Scanner(System.in);
System.out.println("Enter a string");
String s=sc.next();
S=s.toUpperCase(); // [ ERRORS : WRONG FORMAT used for character and String
For String use s.toUpperCase() For character Character.toUpperCase(ch)
int l =s.length();

if(s.charAt(0)==s.charAt(l-1))

// [ MAKE SURE charAt is used to extract 0 (first) and


l-1(last) character .
[ SOME students have used WRONG LOGIC loop and indexOf ??? DO NOT MAKE THESE ERRORS ]

System.out.println(s +" is a SPECIAL WORD");


else
System.out.println(s +" is not a SPECIAL WORD");

}
}

Q 2.
import java.util.*;
class binarysearch

{
public static void main()
{

// binary search integers


[ ERRORS : WRONG SIZE, WRONG ARRAY NAME , n TO BE SEARCHED NOT INPUTTED , LOGIC FOR
DESCENDING USED ]

Scanner sc= new Scanner(System.in);

int i;

int A[]=new int[10]; // array subscripted variable

for(i=0;i<A.length; i++)
{
System.out.println("Enter the value in ascending order for index no"+i); //position is (i+1)

A[i] = sc.nextInt();

System.out.println("Enter the value(key element) to be searched");

int n = sc.nextInt();
int b=0;
int e=A.length-1;
int m;
int flag=0;
while(b<=e)
{
m=(b+e)/2;
if(n>A[m]) // [ERROR INSTEAD OF A[m] ONLY A OR m USED]
b=m+1;
//[ ERRORS : WRONG VARIABLE AND + OR – USED IN THE WRONG PLACE < > WRONG USE ]

else if(n<A[m])
e=m-1;
else // (n==A[m])
{
System.out.println(n+"found at index no"+m);

flag++;
break;

}// compund statement

}// while
if(flag==0) // [ERROR : THIS STATEMENT WAS PUT INSIDE LOOP)

System.out.println(" SORRY ! " +n+" not found");

}
}

Q3.
import java.util.*;

public class chArr1


{
public static void main ()
{
Scanner sc =new Scanner (System.in);
char A[]=new char [10];
int i ; int c= 0; // counter

for (i=0; i<=9;i++)


{
System.out.println("Enter a character for index no"+i);
A[i]=sc.next().charAt(0); // [ instead of 0 loop i was used ]
}
for (i=0; i<=9;i++)

if(Character.isUpperCase(A[i])) // [ERROR statement wrongly used format incorrect]


c++;

} // loop
If(c>0)
System.out.println(“ TOTAL UPPERCASE LETTERS FOUND IN THE ARRAYS “ + c);
else
System.out.println(“ NO UPPERCASE LETTER FOUND IN THE ARRAY”);
}}

Q4.

import java.util.*;

public class chArr1


{
public static void main ()
{
Scanner sc = new Scanner ( System.in );
String A [] = new String [5];
int i ;

for (i=0; i<A.length;i++)


{
System.out.println("Enter a String for index no"+i);
A[i]=sc.next();
}

for (i=0; i<A.length ;i++) // [ ERROR ARRAY LENGTH A.length ]

System.out.println(A[i]+" is stored at index no "+ i+ "it's length is "+ A[i].length()); //// [ ERROR
String array each element length A [i].length() ]
}
}}

Q5.
import java.util.*;

class max
{

public static void main()

Scanner sc= new Scanner(System.in);

int i;
double players[]=new double [11]; // array subscripted variable
double s=0.0;
double av=0.0;
for(i=0;i<players.length; i++)

System.out.println("Enter the value for cell no"+i);

players[i] = sc.nextDouble();
s=s+players[i];

}
double max= players[0]; // [ ERRORS : DECLARE AFTER CREATION OF ARRAY OTHERWISE ARRAY IS
EMPTY]

for(i=0; i<players.length; i++)


{
if (players[i]> max)
{
max= players[i];
}
}
av=s/11.0; // [ERRORS : CALCULATION AND PRINTING SHOULD BE DONE OUTSIDE THE LOOP ]
System.out.println("The average height is "+av);
System.out.println("The max height is "+ max);

}}

Q6.
import j ava.util.*;

class palin
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a String");
String s=sc.next();

System.out.println("Entered String is "+s);


String ns="";
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
ns=ch+ns; //REVERSING
}
System.out.println("reversed String is "+ns);
if(ns.equalsIgnoreCase(s)) // [ERROR: if not sure about the case use a function to ignore case
equalsIgnoreCase() or compareToIgnoreCase()

[ THERE IS NO FUNCTION equalsto() : WRONG USAGE ]

System.out.println(" String is palindrome"+ns);

else
System.out.println(" String is not palindrome "+ns);

}
}

You might also like