ICSE 2014 Sample Paper 1

Computer Applications ICSE Sample Paper 1. These are likely questions different from what has already been asked, but of similar complexity and with some minor twists. The sample papers are designed to ensure the student is able to understand and solve the questions that may come up, using similar concepts as in earlier question papers. As in earlier papers, Questions 1, 2 and 3 are compulsory, and you need to answer 4 out of the remaining 6 questions. Model answers are also provided after each question for your ready reference.

Q1. (a) What do you understand by WORA? [2 marks]

A1. (a) WORA = Write Once Run Anywhere. This is the promise of Java. Once a Java program is compiled, class files in bytecode are created which can be executed on any environment that implements the JRE (Java Runtime Environment), whether it is running on Linux, Android, IOS, Windows, etc.

Q1. (b) Explain two types of comments used in Java programs. [2 marks]

A1. (b)

i) Single-line comment, which starts and ends on the same line. Anything that follows the // on a line is considered a comment.

ii) Multi-line comment, which can span one or more than one line. Anything between /* and */ is considered a comment.

Q1. (c) Explain the difference between the println() and print() functions. [2 marks]

A1. (c) The println() function prints what has to be printed followed by a newline so that the next print() / println() statement starts on a new line. The print() statement does not result in a newline, and the next print() / println() statement starts from where the earlier print() statement ended.

Q1. (d) What do you understand by the term operator precedence? [2 marks]

A1. (d) Operator precedence is a set of rules that determine which part of an expression gets evaluated when. It is most useful when the parenthesis () are missing to help guide the process. According to these rules, for example, The * and / have higher priority over + and -, and + and – have higher priority over the ternary operator ?:.

Q1. (e) A java program named ABC.java has three classes defined inside it: A.java, B.java, C.java. The class A.java is a public class. Will the program compile? If yes, how many class files will be created? If no, why not? [2 marks]

A1. (e) The program will not compile. Since A.java is a public class, the name of the program file must be A.java. The program file is named ABC.java. A public class must exist in a file which has the same name as that of the class.

Q2. (a) What do you understand by wrapper class? Give an example. [2 marks]

A2. (a) Everything in Java is an object … almost. The exceptions are the 8 primitive data types such as byte, short, int, etc. Many times, it is useful to treat the primitive data type values as objects. Wrapper classes are classes that correspond to the 8 primitive data types. Automatic conversions between primitive to wrapper equivalent (boxing) and wrapper equivalent to primitive data type value (unboxing) happens in Java. The Wrapper classes also provide useful static methods, such as Integer.parseInt() and Double.parseDouble() that accept a String and return the int / double values.

An example of a wrapper class is Integer, for the primitive data type int.

Q2. (b) Differentiate between bubble sort and selection sort techniques. [2 marks]

A2. (b)

Bubble Sort Selection Sort
Higher number of swaps Lower number of swaps
Maximum number of swaps for large data sets is approx. n2 Maximum number of swaps for large data sets is approx. n
Less efficient for large data sets since swapping is an expensive operation More efficient for large data sets since swapping is less that bubble sort
Swapping happens for each value check Swapping happens once per loop iteration, since the index of the max/min value is set in the iterations

Q2. (c) Explain the difference between length() and length. [2 marks]

Q2. (c) The length() method is used on String values to compute the size of the string, whereas length is used with arrays to determine the size of the dimension of that array. For example, if String[] s = {“Hello”, “Goodbye”}; is an array of Strings, s.length is 2, and s[0].length() is 5, and s[1].length() is 7.

Q2. (d) What are the two clauses that form part of the try statement dealing with exception handling? [2 marks]

A2. (d) Two two clauses are catch and finally.

Q2. (e) Explain what you understand by signature of a function. [2 marks]

A2. (e) The signature of a function is what makes it unique from any other function in the same class. Two functions in the same class can have the same name, as long as the number and the order of the data types of those functions is different. This combination of the name of the function, the number and order of the data types, is called the signature of a function. This is useful in determining which function gets called, a process known as function overloading.

Q3. (a) Write a Java statement to create an object named apple of class Fruit. [2 marks]

A3. (a) Fruit apple = new Fruit();

Q3. (b) Write a statement that initializes a one-dimensional double array named d with the values 1, 4, 9, and 16. [2 marks]

A3. (b) double[] d = { 1.0D, 4.0D, 9.0D, 16.0D };

Q3. (c) What is the maximum value that (int)( Math.random() * 6 ); can evaluate to?

A3. (c) 5

Explanation: Math.random() returns a number from 0 to just less than 1.0 (0 < = number < 1.0). This means than the number, at a maximum, can be 0.99999 must never 1. So, 5 times that number will be 5.9999… but never 6.0. When the (int) type case is applied, this will knock off the fraction part, and leave a maximum of 5 only.

Q3. (d) What is the return type of the following methods?

i) toUpperCase()

ii) toLowerCase()

iii) equals()

iv) compareTo()

[4 marks]

A3. (d)

i) String

ii) String

iii) boolean

iv) int

Q3. (e) What is the output of the following code snippet?

int x = 2;
x += x++ * x++ * x++;
System.out.println(x);

[2 marks]

A3. (e) 26

Working: 2 is added to the result due to x +=. Therefore, the expression evaluates to x = 2 + (2++*x++*x++) = 2 + (2 * 3++ * x++) = 2 + (2 * 3 * 4++) = 2 + (2 * 3 * 4) = 2 + 24 = 26.

Q3. (f) Write the statement z = (x > y) ? x : y; using if construct. [2 marks]

A3. (f)

if(x > y)
  z = x;
else
  z = y;

Q3. (g) What is the output of the following code snippet?

String s1 = "Batman and Robin";
String s2 = "The Cat wont move the cheese";
String s3 = s2.substring( s2.lastIndexOf("C"), s2.lastIndexOf("C") + 3 );
String s4 = s1.replace( "Bat", s3 + "wo" );
System.out.println( s4 );

[3 marks]

A3. (g) Catwoman and Robin

Q3. (h) What is the output if the following are invoked on the class below:

i) Q3.function(4);

ii) Q3.function();

iii) Q3.function(‘A’);

class Q3
{
    public static void function()
    {
        function(0);
    }

    public static void function(int x)
    {
        System.out.println(x);
    }
}

[3 marks]

A3. (h)

i) 4

ii) 0

iii) 65

Q4. Define a class Point that has the following structure:

Data members / instance variables: x and y of type integer – these are the X and Y coordinated of the point

Parameterized Constructor: the data members must be initialized using a 2-argument parameterized constructor

Member methods:

display() – to display the coordinates of the Point object in (x, y) format

move(int, int) – that accepts two integer arguments and changes the x,y of the Point object by the value of the arguments passed

move(Point) – overloaded to behave similar to move(int, int) – it changes the x,y of the Point object by the x and y of the Point argument passed to it.

Call the above functions in your program.

[15 marks]

A4.

class Point
{
    // data members
    int x, y;

    // 2-argument parameterized constructor
    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    // display
    public void display()
    {
        System.out.println( "(" + x + ", " + y + ")" );
    }

    // overloaded move() #1
    public void move(int x, int y)
    {
        this.x += x;
        this.y += y;
    }

    // overloaded move() #2
    public void move(Point p)
    {
        this.move(p.x, p.y);
    }

    // entry point main method
    public static void main(String[] args)
    {
        Point p1 = new Point(3, 4);
        Point p2 = new Point(5, 10);

        p1.display();
        p2.display();
        p1.move(3, 4);
        p1.display();
        p1.move(p2);
        p1.display();
    }
}

Sample output:

sample0104

Q5. Write a program that asks the user to enter an integer (N). Create a single-dimensional array of N double values. Ask the user to enter the N double values to populate this array. Sort this array in reverse (descending) order using the selection sort method, and print the same on a single line, each element separated by a space. [15 marks]

A5.

import java.util.*;
class Q5
{
    public static void main(String[] args)
    {
        // user input
        Scanner sc = new Scanner( System.in );
        String temp;
        System.out.print("Enter number of elements (N): ");
        int N = sc.nextInt();
        temp = sc.nextLine(); // for the trailing newline
        // create the array
        double[] d = new double[N];
        // populating the array
        System.out.print("Enter the " + N + " elements: ");
        int i, j;
        for(i=0; i<N; i++)
        {
            d[i] = sc.nextDouble();
        }
        temp = sc.nextLine();

        // perform the selection sort
        // in reverse order
        int minIndex = 0;
        double swapper;
        for(i=0; i < (N-1); i++)
        {
            minIndex = 0;
            for(j=1; j<=(N-1-i); j++)
            {
                if(d[minIndex] > d[j])
                  minIndex = j;
            }
            // do the swap using temp variable swapper
            swapper = d[minIndex];
            d[minIndex] = d[N-1-i];
            d[N-1-i] = swapper;
        }

        // display the output
        System.out.print("Sorted output: ");
        for(i=0; i<N; i++)
          System.out.print(d[i] + " ");
        System.out.println();
    }
}

Sample output:

sample0105

Q6. A prominent builder has announced the launch of a property which starts at 4000 Rs per sft (square foot) for the 1st floor floor flat. The price per sft increases by Rs. 50 per floor up to and including the 10th floor. From the 10th floor upwards, the price per sft increases by Rs. 100 per floor. There are two types of flats: 2BHK and 3BHK. The 2BHK flats have a saleable area of 1500 sft, and the 3BHK flats have a saleable area of 2000 sft. The building has 20 floors. Write a program that prints the rate of each floor, and the cost of each type of flat for each of the floors, in the format shown below:

Floor No. Rate per sft. Price of 2BHK Price of 3BHK
1
2

[15 marks]

A6.

class Q6
{
    public static void main(String[] args)
    {
        // set the rates array (Rs. per sft)
        int[] rates = new int[21]; // use 1 to 20 floors
        int i;
        rates[1] = 4000;
        for(i=2; i<rates.length; i++)
        {
            if(i<=10)
              rates[i] = rates[i-1] + 50; // 2nd to 10th floors
            else
              rates[i] = rates[i-1] + 100; // 11th floor onwards
        }

        // send the header
        System.out.println("Floor No. Rate Per SFT Price of 2BHK Price of 3BHK");
        System.out.println("--------- ------------ ------------- -------------");
        for(i=1; i<rates.length; i++)
        {
            printInt(i, 9+1);
            printInt(rates[i],12+1);
            printInt(rates[i]*1500,13+1);
            printInt(rates[i]*2000,13+1);
            System.out.println();
        }
    }
    // utility method to print an int in a field width
    // left padded with spaces
    public static void printInt(int n, int width)
    {
        String s = "" + n;
        int spaces = width - s.length();
        while(spaces > 0)
        {
            System.out.print(" "); // one space
            spaces--;
        }
        System.out.print(n);
    }
}

Output:

sample0106

Q7. Write a program that asks the user to enter a sentence. Ignoring the case, print those words that occur maximum number of times in the sentence. For example:

INPUT: Is the question of why is the main method in Java called main too difficult?

OUTPUT: Maximum frequency: 3 Word(s) are: IS THE MAIN

[15 marks]

A7.

import java.util.*;
class Q7
{
    public static void main(String[] args)
    {
        // user input
        Scanner sc = new Scanner( System.in );
        System.out.print("Enter a sentence: ");
        String sentence = sc.nextLine().toUpperCase();

        // array to store the words and their frequency
        // cannot exceed number of characters in the sentence
        String[] words = new String[ sentence.length() ];
        int[] freq = new int[words.length];
        int wordCount = 0; // initially zero

        // split into words
        // and populate the words[] and freq[] arrays
        String word;
        int i;
        boolean found;
        int foundIndex = 0;
        StringTokenizer st = new StringTokenizer(sentence, " .,;()?!");
        while( st.hasMoreTokens() )
        {
            word = st.nextToken();
            found = false;
            foundIndex = -1;
            for(i=0; i<wordCount; i++)
            {
                if( words[i].equals( word ) )
                {
                    found = true;
                    foundIndex = i;
                    break;
                }
            }
            if(found)
              freq[foundIndex]++;
            else
            {
                words[wordCount] = word;
                freq[wordCount] = 1;
                wordCount++;
            }
        }

        // compute the max freq
        int maxFreq = 0;
        for(i=0; i<wordCount; i++)
        {
            maxFreq = (maxFreq < freq[i]) ? freq[i] : maxFreq;
        }

        // print words with the maxFreq occurrence
        System.out.print("Maximum frequency: " + maxFreq + " Word(s) are: ");
        for(i=0; i<wordCount; i++)
          if(freq[i] == maxFreq)
            System.out.print(words[i] + " ");
        System.out.println();
    }
}

Sample output:

sample0107

Another program without StringTokenizer:

import java.util.*;
class Q7_02 // second way without StringTokenizer
{
  public static void main(String[] args)
  {
    // user input
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a sentence: ");
    String sentence = sc.nextLine().toUpperCase();

    // pass the sentence to a function that converts it
    // into words and does the needful
    // add a space at the end to ensure the last word is included
    action( sentence + " " );
  }

  public static void action( String s )
  {
    int len = s.length();
    // maximum number of words will be the length of the sentence.
    // this is a worst-case scenario.
    String[] words = new String[ len ]; 
    int[] freq = new int[ len ];
    int i, j;
    // initialize the frequency array
    for(i=0; i < len; i++)
    {
      freq[i] = 0;
    }

    int noOfWords = 0;
    String currentWord = "";
    for(i=0; i < len; i++)
    {
      char ch = s.charAt(i); // extract one character
      boolean isWordSeparator = false;
      switch(ch)
      {
        case ' ': // space
        case ',':
        case '!':
        case '.':
        case '?':
        case ':': // no hyphen, since hyphenated words are allowed
        case '"':
          isWordSeparator = true;
          break;
      }
      if(!isWordSeparator)
      {
        currentWord = currentWord + ch;
      }
      else
      {
        if(currentWord.length() > 0)
        {
          int index = -1;
          boolean found = false;
          for(j=0; j < noOfWords; j++)
          {
            if(words[j].equals(currentWord))
            {
              found = true;
              index = j;
              break;
            }
          } 
          if(!found)
          {
            // add to the array
            words[noOfWords] = currentWord;
            index = noOfWords;
            noOfWords++;
            
          }
          // increase the frequency
          freq[index]++;
          // reset the variable for the next char
          currentWord = ""; 
        }
      }
    }
    int maxFreq = 0;
    int maxCount = 0;
    for(i=0; i < noOfWords; i++)
    {
      if(maxFreq < freq[i])
      {
        maxFreq = freq[i];
        maxCount = 0;
      }
      if(maxFreq == freq[i])
      {
        maxCount++;
      }
    }
    // print all words with the maximum frequency
    System.out.print("Maximum frequency: ");
    System.out.print(maxCount + " Word(s) are: ");
    for(i=0; i < noOfWords; i++)
    {
      if(freq[i] == maxFreq)
      {
        System.out.print(words[i] + " ");
      }
    }
    System.out.println();
  }
}

Q8. Write a menu driven program that performs the following functions (use switch..case):

i) Ask the user to enter two numbers and check if they are amicable numbers or not. A set of numbers (n1 and n2) are amicable if the sum of the proper factors of n1 is equal to n2, and the sum of the proper factors of n2 is equal to n1. A proper factor of a number is all factors of that number including 1, but not the number itself.

ii) Ask the user to enter a word, and print all 3 letter combinations of that word, including repeats, on a single line, each combination separated by spaces.

[15 marks]

A8.

import java.util.*;
class Q8
{
    public static void main(String[] args)
    {
        char menuOption = ' '; // space
        do
        {
            menuOption = askMenuOption();
            switch(menuOption)
            {
                case 'A':
                  doAmicable();
                  break;
                case 'C':
                  do3LetterCombos();
                  break;
                case 'X':
                  System.out.println("Exiting program. Thank you!");
                  break;
            }
        }while( menuOption != 'X' );
    }
    // ask the user to enter a menu option
    // reask if wrong option is entered
    // return the option chosen
    public static char askMenuOption()
    {
        Scanner sc = new Scanner( System.in );
        char option = ' '; // space
        do
        {
            System.out.print("Enter A-Amicable, C-3-letter, X-Exit: ");
            option = sc.nextLine().toUpperCase().charAt(0);
            if( "ACX".indexOf(option) < 0 )
              System.out.println("Incorrect option. Try again...");
        }while( "ACX".indexOf(option) < 0 );
        return option;
    }
    // amicable number process
    public static void doAmicable()
    {
        int n1 = askInt("Enter number n1: ");
        int n2 = askInt("Enter number n2: ");
        int sof1 = getSumOfFactors(n1);
        int sof2 = getSumOfFactors(n2);
        if( (n1 == sof2) && (n2 == sof1) )
          System.out.println(n1 + " and " + n2 + " are amicable numbers");
        else
          System.out.println(n1 + " and " + n2 + " are not amicable numbers");
    }
    // ask user to enter an int
    // display parameter 1 as the prompt
    public static int askInt(String prompt)
    {
        Scanner sc = new Scanner( System.in );
        System.out.print(prompt);
        int n = sc.nextInt();
        String temp = sc.nextLine(); // for the trailing newline
        return n;
    }
    // return sum of proper factors
    public static int getSumOfFactors(int n)
    {
        int i, sum=0;
        for(i=1; i<n; i++)
          if( (n%i) == 0 )
            sum += i;
        return sum;
    }
    // 3 letter combo
    public static void do3LetterCombos()
    {
        Scanner sc = new Scanner( System.in );
        System.out.print("Enter a word: ");
        String word = sc.nextLine().toUpperCase();
        int i, j, k;
        String s1, s2, s3;
        String combo;
        for(i=0; i<word.length(); i++)
          for(j=0; j<word.length(); j++)
            for(k=0; k<word.length(); k++)
              if( (i!=j) && (j!=k) && (i!=k) )
              {
                  s1 = word.substring(i,i+1);
                  s2 = word.substring(j,j+1);
                  s3 = word.substring(k,k+1);
                  combo = s1 + s2 + s3;
                  System.out.print(combo + " ");
              }
        System.out.println();
    }
}

Sample output:

sample0108

Q9. Given that 1st Jan 2014 is a Wednesday, compute the day of Feb 28th, 2021. A year is a leap year if it is divisible by 4. There is one exception to this rule: If a year is divisible by 100, but not by 400, it is not a leap year (e.g. 2100, 2200, 2300, 2500, etc.) However, since 2400 is divisible by 400 it is a leap year. [15 marks]

A9.

class Q9
{
    public static void main(String[] args)
    {
        int dd = 1, mm = 1, yyyy = 2014;
        String[] weekDayName = { "Monday", "Tuesday",
            "Wednesday", "Thursday", "Friday",
            "Saturday", "Sunday" 
        };
        int day = 2 ; // Wednesday

        while( !( (dd == 28) && (mm == 2) && (yyyy == 2021) ) )
        {
            dd++;
            day++;
            if( day == 7 )
              day = 0; // 0 is Monday, 6 is Sunday
            switch( mm )
            {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                  if( dd > 31 )
                  {
                      dd = 1;
                      mm++;
                      if( mm > 12 )
                      {
                          mm = 1;
                          yyyy++;
                      }
                  }
                  break;
                case 4:
                case 6:
                case 9:
                case 11:
                  if( dd > 30 )
                  {
                      dd = 1;
                      mm++;
                      if( mm > 12 )
                      {
                          mm = 1;
                          yyyy++;
                      }
                  }
                  break;
                case 2:
                  int daysInMonth = getFebDaysInMonth(yyyy);
                  if( dd > daysInMonth )
                  {
                      dd = 1;
                      mm++;
                      if( mm > 12 )
                      {
                          mm = 1;
                          yyyy++;
                      }
                  }
                  break;                  
            }
        }
        System.out.println("Week day name: " + weekDayName[day]);
    }
    // return days on Feb of the year passed ... 28 or 29
    public static int getFebDaysInMonth(int year)
    {
        if( (year%4) != 0 ) // not multiple of 4
          return 28;
        // if code reaches here, year is a multiple of 4
        if( (year%100) != 0 ) // not multiple of 100
          return 29; // leap year
        // if code reaches here, year is a multiple of 100
        if( (year%400) != 0 ) // not multiple of 400
          return 28;
        return 29; // multiple of 400
    }
}

Output:

sample0109

78 thoughts on “ICSE 2014 Sample Paper 1

    1. Dear Juthika

      Scanner class is not required since the date is already given in the question. You would use the Scanner class to read input from the User. For example, “Enter the date: ” and then use the Scanner class to capture the date values.

      regards

      Ajay Pherwani

    1. Dear Avni (Jyoti.Sunny)

      Q3(c) is as follows:

      Math.random() returns a number from 0 to 0.99999 (but less than 1)

      So, 6 times that number can be, at a maximum, 5.999999 (but never 6).

      Doing a (int) typecast on this will knock off the fraction part after the decimal leaving a maximum value of 5.

      I trust this answers your query.

      regards
      Ajay Pherwani

    1. Dear Anaya
      i will put an explanation in a day or two below the program
      regards
      Ajay Pherwani

    1. Dear Raza

      Very difficult to do Q7 of Sample Paper 1 without arrays. How will you know which word has been considered and so on? Keeping track of such things without arrays is a problem.

      Tell me where you are getting confused and I will try and help.

      regards

      Ajay Pherwani

    1. Dear Leharika

      Q3(c) of Sample Paper 1:

      Math.random() returns a double value from 0.00 included until 0.9999999 (just less than 1.0, but NOT 1.0)

      Hence, 6 times that number can at most be just less than 6 (but never 6).

      The (int)typecast on this result, will knock off the fraction part.

      Hence the maximum number will be 5.

      Regards
      Ajay Pherwani

    1. Dear Kaustav

      I have updated the explanation inside Q3(c) of Sample Paper 1.

      regards Ajay Pherwani

      1. sir please explain…me question no 4…..i am not understanding the program…and also the “this” keyword

  1. pl. explain q3[g] ….this statement

    String s3 = s2.substring( s2.lastIndexOf(“C”) , s2.lastIndexOf(“C”) + 3 );

    what does the “,” indicate?

    1. Dear Purva

      There are two parameters to the substring method, which are separated by a comma.

      The first parameter is s2.lastIndexOf(“C”), which is an integer that indicates the starting index

      The second parameter is s2.lastIndexOf(“C”)+3 which is the ending index

      The outer s2.substring() function will return a string from the first parameter value till the last parameter value less 1 position.

      regards

      Ajay Pherwani

    1. Dear Arushi

      You need to be more specific. Where exactly are you stuck in the last program?

      Try reading the question slowly, and understand what the rules are. All I have done is programmed the rules. You can try it your own way as well,.

      regards

      Ajay Pherwani

    1. Dear Suhas S Raina

      I have designed some questions, trying to provide slightly more difficult questions, in case the Board Papers are tougher. I dont set the paper and hence I dont know what will be asked. This is my interpretation based on 6 years of teaching

      regards

      Ajay

  2. Ur simply doing a FAB job sir..
    But in i haven’t studied stringtokenizer class of util package so kindly post some way using io package and string class to do Q7 i want to check my logic with your point of view of doing it..
    Regards!

    1. Dear Vijnivedita

      Alternative answer posted as class Q7_02. Have a look!

      regards
      Ajay Pherwani

  3. it help me very glad, sir, thanks many….
    i am a student in ICSE and pure in java
    if u you send me some importance sample Question [program which is more importance] i will be pass
    thanks again and again

  4. sir,
    thank you…
    i am too tensed about computer exam….
    i am poor in computer even though i am scoring good marks in all other subjects…
    i request you to give me some tips so that i can score better marks in computer…
    looking forward for reply….

  5. dear ajay sir,
    can u pls give the difference between
    1. acessor method and mutator method
    2. concatenatioin and truncation
    3. subscript and subcripted variable

    1. sir i know these questions are out of the paper but if u could pls tell me the answer of my above questions asked on 22Feb
      sorry but pls help

      1. Dear Jyoti

        1. Accessor methods return the value of an instance variable of an object. For example, e.getName() will return the value of the Employee object “e”. They do not change the value of the instance variables, and hence the state of the object remains the same. Accessor methods are also known as “getter” methods.
        Mutator methods change the value of an instance variable. For example, e.setName(“Jyoti”) will set the “name” instance variable of the Employee object “e” to “Jyoti”. They change the state of the object. Mutator methods are also called “setter” methods.

        2. Concatenation is the joining of two values, normally seen with String objects. For example, if s1 = “Jyo” and s2=”ti”, then String s3 = s1 + s2 = “Jyoti”.
        Truncation is the knocking off, of part of a value. In String variables, the substring() method can be used. for example” “Jyoti”.substring(0,3) will return a String “Jyo”. Truncation also happens when a float or double value is explicitly typecast into an int or long variable; here the fractional component gets knocked off. For this, an explicit typecast is needed.
        3. Subscript is a value used to identify an index of an array. For example, names[2] will identify the 3rd element of the array. A subscripted variable is a variable that is defined as an array. For example, with the code int[] x = new int[3]; –> here x is a subscripted variable that can have subscripts of 0, 1, and 2.

        Regards

        Ajay Pherwani

    2. Dear Jyoti

      1. Accessor methods return the value of an instance variable of an object. For example, e.getName() will return the value of the Employee object “e”. They do not change the value of the instance variables, and hence the state of the object remains the same. Accessor methods are also known as “getter” methods.
      Mutator methods change the value of an instance variable. For example, e.setName(“Jyoti”) will set the “name” instance variable of the Employee object “e” to “Jyoti”. They change the state of the object. Mutator methods are also called “setter” methods.

      2. Concatenation is the joining of two values, normally seen with String objects. For example, if s1 = “Jyo” and s2=”ti”, then String s3 = s1 + s2 = “Jyoti”.
      Truncation is the knocking off, of part of a value. In String variables, the substring() method can be used. for example” “Jyoti”.substring(0,3) will return a String “Jyo”. Truncation also happens when a float or double value is explicitly typecast into an int or long variable; here the fractional component gets knocked off. For this, an explicit typecast is needed.
      3. Subscript is a value used to identify an index of an array. For example, names[2] will identify the 3rd element of the array. A subscripted variable is a variable that is defined as an array. For example, with the code int[] x = new int[3]; –> here x is a subscripted variable that can have subscripts of 0, 1, and 2.

      Regards

      Ajay Pherwani

  6. 1. State and explain the multiple branch statement provided by Java.
    2. Differentiate between coercion and casting
    3. Which keyword is used to raise an exception?
    4. What does System.in.read() return?
    5. State any two IOException classes.
    6. How many iterations are involved while bubble sorting an array of 5 integers?
    7. State the difference between class, instant, local and static and non-static variables.

  7. hello sir,
    i had a few doubts…
    1) what if i don’t add the suffix D after every element of the array… (referring to q 3(b))
    2)i didn’t get q 3(g)… i’m getting ‘Chewoman and Robin’ as my output…..

    1. Dear Komal

      Q3(b): The D is optional since 1.0 float will automatically convert to double. But it is preferred.

      Q3(g): Check the case of the “C”. It is uppercase, and hence the value of s3 is “Cat” and not “che”.

      regards

      Ajay Pherwani

  8. Sir
    The output of question 3(e) is 26. will it not be 27 because in the printing statement x is there so for the last (x++) the increment is not done!!!

    1. Dear Pratyaksha

      The output is shown as 26 itself, not 27. 26 is the correct answer.

      regards

      Ajay Pherwani

  9. Hi sir.plz explain the difference between ++x n x++…..sir tell it soon plz as I am going back to the hostel….

    1. Dear Rashid

      This is answered in the Theory questions and the ICSE question papers, under pre-increment and post-increment.

      regards

      Ajay

  10. sir..cld u pls suggest some imp types of programs that could come for icse (not the programs but just the types).I would be overwhelmed if you replied…thank you

    1. Dear Oyeshi

      I dont set the papers so I dont know, but normally:

      1. Sorting/Searching
      2. Patterns / sequences / series
      3. Defining Class / Object / Constructor / Instance Variables / Methods
      4. Complex if … elseif (discount table, taxi fare table, and so on.)
      5. String programs with manipulations
      6. Menu programs … number algorithms … prime / automorphic / palindrome / Krishnamurthi numbers etc.

      regards

      Ajay

  11. Thank you sir,
    for the previous reply it is very helpful…..but sir i have another querie.Suppose when we are doing palindrome is this possible:
    import java .io.*
    class Palindrome
    {
    public static void main (String s[])throws IOException
    {
    Input Stream Reader read=new Input Stream Reader (system.in)
    Buffer Reader in=new Buffer Reader (read)
    string s,s1;
    System.out.prinil(“Enter a word of your choice”);
    s=Integer.parseInt(in.readline());
    s1=s.reverse();
    {
    if(s==s1)
    System.out.println(s + “is a palindrome”);
    else
    System.out.println(s +”is not a palindrome”);
    }}}
    Actually when i showed it to one of my friends she told that her tuition teacher and her tuition teacher said that this program will not be accepted as i am not using any logic using reverse() function will not do . Sir is this really true …wil i not be given marks in icse if i do by this method?
    Sir pls reply..thank you

    1. Dear Parth

      Mainly the theory, exception handling, the class hierarchy, the main methods, and so on.

      regards

      Ajay

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>