Answer:
The function in Java is as follows:
public static void printMessage(String lineOne, String lineTwo, int lines){
for(int i = 1;i<=lines;i++){
if(i%2 == 1){
System.out.println(lineOne);
}
else{
System.out.println(lineTwo);
}
}
}
Explanation:
This defines the function
public static void printMessage(String lineOne, String lineTwo, int lines){
This iterates through the number of lines
for(int i = 1;i<=lines;i++){
String lineOne is printed on odd lines i.e. 1,3,5....
if(i%2 == 1){
System.out.println(lineOne);
}
String lineTwo is printed on even lines i.e. 2,4,6....
else{
System.out.println(lineTwo);
}
}
}
To call the function from main, use:
printMessage("Hi", "Karel", 5);