(a) Differentiate between if else if and switch-case statements

ICSE Class 10 Computer Applications PYQ · 2019 Paper · Section A

21 Mark · 2019 · Section A · 2019 Paper

(a) Differentiate between if else if and switch-case statements

Show SolutionHide Solution↓
if else ifswitch-case
if else if can test for any Boolean expression like less than, greater than, equal to, not equal to, etc.switch-case can only test if the expression is equal to any of its case constants.
if else if can use different expression involving unrelated variables in its different condition expressions.switch-case statement tests the same expression against a set of constant values.

(b) Give the output of the following code:

String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);

Output of the above code is:

2019

Both Integer.parseInt() and Integer.valueOf() methods convert a string into integer. Integer.parseInt() returns an int value that gets assigned to a. Integer.valueOf() returns an Integer object (i.e. the wrapper class of int). Due to auto-boxing, Integer object is converted to int and gets assigned to b. So a becomes 20 and b becomes 19. 2019 is printed as the output.

(c) What are the various types of errors in Java?

There are 3 types of errors in Java:

  1. Syntax Error
  2. Runtime Error
  3. Logical Error

(d) State the data type and value of res after the following is executed:

char ch = '9';
res= Character.isDigit(ch);

Data type of res is boolean as return type of method Character.isDigit() is boolean. Its value is true as '9' is a digit.

(e) What is the difference between the linear search and the binary search technique?

Linear searchBinary search
Linear search works on sorted and unsorted arrays.Binary search works on only sorted arrays.
In Linear search, each element of the array is checked against the target value until the element is found or end of the array is reached.In Binary search, array is successively divided into 2 halves and the target element is searched either in the first half or in the second half.
Linear Search is slower.Binary Search is faster.
← Previous questionNext question →

Browse the free Computer Applications sample bank