Wrapper Classes Exercise: Cognizant Technology Solutions
Wrapper Classes Exercise: Cognizant Technology Solutions
Wrapper Classes
Exercise
Statement # 1: Few problem solutions have been provided for associates should analyze the
program and write down the program output. This will enhance the analyzing skills of associates
and also understand “why” part of java programming feature. The associates can then try
running the program in eclipse and check if the output with what they have written.
Stamen # 2: There are some problem statements provided similar to the final assessment and
associates need to solve it. This will enhance the programming skills of the associates.
IMPORTANT: These exercises will gear you up for the core java assessment so please
develop/analyze the exercise independently. In case you are stuck up reach out to the trainers.
Exercises:
1. What is the output of compiling and running the following code?
class Test {
public static void main(String arg[]) {
Integer x = 1000;
long y = 1000;
Integer z = 1000;
System.out.println(x==y);
System.out.println(x==z);
}
}
2
Wrapper Classes Exercise 2012
2. What is the output?
class Tester {
Integer x = 0;
Integer y = 0;
x++;
class Titanic {
Boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
System.out.print("alpha ");
System.out.print("beta ");
}}
3
Wrapper Classes Exercise 2012
4. What is the output?
class Tester {
new Tester().go();
void go() {
short s = 7;
System.out.println(doX(7,7));
4
Wrapper Classes Exercise 2012
5. Given the code. What is the result?
6. Create a class that performs the conversion between data type values.
5
Wrapper Classes Exercise 2012
7. Create a class that finds the smallest of an array of numbers.
9. Create a class that contains method to accept an array and convert all the even members to the
next odd (even+1) and all the odd numbers to the previous even (odd-1).
10. Create a class that contains method which can remove the specified character from the given
character array
6
Wrapper Classes Exercise 2012
11. Create a class that contains method capable of modifying in an array such a way that the new
array contains elements which are the product of two neighboring columns in the original array.
Last element can be left as it is.