Use method overriding to write two methods called printArray. On should take an int array and the other should take a double array. Both should print the array they are given as an argument
public class Main
{
public static void main(String[] args) {
int integerArray[]={5,6,8,3};
double doubleArray[]={23.3,6.6,8.3,3.3};
System.out.println("Integer array: ");
printArray(integerArray);
System.out.println("\nDouble array: ");
printArray(doubleArray);
}
static void printArray(int integerArray[]){
for(int i=0;i<integerArray.length;i++){
System.out.println(integerArray[i]);
}
}
static void printArray(double doubleArray[]){
for(int i=0;i<doubleArray.length;i++){
System.out.println(doubleArray[i]);
}
}
}
Comments
Leave a comment