Java Learners
Here  is the Array Code  I assume you have a fair knowledge  of arrays as you start this section .
Study the following code :
Question 1:
// Array Quiz 1 :
package iknowjava; public class arrayQz1 { /** * @param args */ public static void main(String[] args) { int intArray[]={1,2,3,4,5}; for (int intCounter=0; intCounter<10;intCounter++) { System.out.println("\n Array Element["+intCounter+ " ]:" + intArray[intCounter]); } } }
//Code ends here
What is the output :
 1. The program compiles and runs without error
 2. The program does not compile
3. The program compiles but throws a runtime error
4. The program runs and along with array elemets throw an error
Question 2 :
package iknowjava; public class arrayQz1q2 { public static void main(String[] args) { int intArray[]={1,2,3,4,5,10.2}; for (int intCounter=0; intCounter<intArray.length;intCounter++) { System.out.println("\n Array Element["+intCounter+ " ]:" + intArray[intCounter]); } } }
// Code Ends
1. The output is 1,2,3,4,5,10.2
2. There are compile time errors
3. There are run time errors
4. An exception is thrown on running
Question3:
Check the following code and tell the output :
public static void main(String[] args) { // long intArray[]= {1,2,3,4,5,10.2}; for (int intCounter=0; intCounter<intArray.length;intCounter++) { System.out.println("\n Array Element["+intCounter+ " ]:" + intArray[intCounter]); } }
1. No errors
2. Compile time error
3. Runtime error
4. The output shows all the elements of array.
Question 4:
public class arrayQz1q4 { /** * @param args */ public static void main(String[] args) { int newA=5; int[]bigArray=new int[newA]; int[] m ={12,34,56,7,8,90}; int big=m[0]; for (int j=1; j big) big=m[j]; } System.out.println("Highest = " + big); } }
1. Runs with compiler warning
2. Compiles but not run
3.Displays the highest number
4. Displays the lowest number in arrays
 
 
 
  Solution to the Quiz