Gauging your knowledge of Java

Statements and for-loops

  • What is the output of the following code fragment:

       int sum = 1;
       for (int i = 0; i <= 5; sum = sum + i++);            
       System.out.print(sum);
    

Gauging your knowledge of Java

Operators

  • If a and b are int variables such that b != 0 then which of the following expressions is always equivalent to a%b ?

      1. (a/b)*b
      2. a - (a/b)*b
      3. a - a/b
      4. (double)a/b - a/b

Gauging your knowledge of Java

References

  • Which of the following will always correctly check whether an object variable obj contains a null reference?

      1. obj.equals(null)
      2. null == obj
      3. obj = null
      4. null.equals(obj)
      5. None of the above

Gauging your knowledge of Java

Primitive types

  • A variable int x stores:

      1. A reference to an int value
      2. An integer value
      3. The identifier "x"
      4. An address of an int variable

Gauging your knowledge of Java

Object types

  • A variable String x stores:

      1. A reference to an object of the String class
      2. An object of the String class
      3. The identifier "x"
      4. A value of the String class

Gauging your knowledge of Java

Programming

  • Write a method named inorder( ) that:

      • takes an array of integers as a parameter and

      • returns the count of elements that are smaller than the element immediately following it.

    Example:

       Input array:  3, 7, 8, 5, 4, 9
    
       Method returns 3, because:
    
                     3, 7, 8, 5, 4, 9            
    		 3, 7, 8, 5, 4, 9
    		 3, 7, 8, 5, 4, 9