Practice Problems

 
1)	What will be the output from the following code:
  char [] letters={'a','b','c','d'}; 
  letters[2]=letters[1]
  System.out.println(letters[1]);
  

2) Given:
          int array[ ]={9,5,8,14,2}; int sum=0; double result=0;
          for(int count=0;count <array.length;count++)
                sum=sum+array[count];
          result=sum/array.length;
          System.out.print(result);

What will be the value of result:

A.	The sum of all the values in the array added together
B.	The average of all the values in the array
C.	0
D.	5, since there are 5 values in the array

3)What will be the output of the following code:

        int array[ ]=new int[5];
        for(int count=0;count<array.length;count++)
        {
                array[count]=count*3;
                System.out.print(array[count]+" ");
        }
	
A.	0 3 6 9 12
B.	0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
C.	3 6 9 12 
D.	0 3 6 9 12 15

4)	What will be the output of the following code:

	int array[]=new int[10];
	for(int count=0;count<array.length;count++)
	{
		array[count]=count*2;
		System.out.print(array[count]+" ");
	}