Fill in this function that takes three parameters, two Strings and an int. 4- // Write some test function calls here! The Strings are the message that should be printed. You should alternate printMessage("Hi", "Karel", 5); between the Strings after each line. The int represents the total number of lines that should be printed. public void printMessage(String lineOne, String lineTwo, in For example, if you were to call 19.
printMessage("Hi", "Karel", 5);
// Start here! 12 the function should produce the following output:
Hi
Karel
Hi
Kare

Answers

Answer 1

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);


Related Questions

Other Questions
-(-125) = ___can someone answer this WHAT IS THIS PLSSSSSS HELP I dont know the answer to this question, I need help the question is in the picture! If x = 7 and y= 3 , find i) x+y ii) xy iii) x2 + y2 WHAT IS THE ANSWER hypothesis: what causes an object to slow down after no longer being pushed? answer: frictionbased on your hypothesis, circle all surfaces that will cause a moving cart to slow down after the fan is turned off.(select all that apply)No Friction Metal Cement Woodhelp, i will select brainliest to the best answer. 50 points...THE RIGHT ONE QWIAEJKNF 16+x=-34Solve the equation for the value of the variable show all work help please:):) SOMEONE HELP MEH...Tonya has 5/9 yards of ribbon and is sharing it with Terri by cutting it in half. How much ribbon will each girl have?Group of answer choices1_1/95/95/1845 How are europeans addressing the decline in the North Atlantic fishing industry? if three distinct numbers have a sum of 10 and a product of 20, what is their median What is the answer above? A 15.0 kg bowling ball rolling at 3 m/s is stopped by a constant force of 11.2 newtons. Calculate the time the force must act on the bowling ball to stop it. Solve for y in the equation C = 5x +y Need help!!!Will give brainliest for answerGive oxidation and reduction half-reactions to the equation provided When performing a self-assessment, it is useful to ask yourself whether you _________.a.Really enjoy what you do at workb.Think your job pays enoughc.Can achieve your career goals in the same companyd.All of the abovePlease select the best answer from the choices providedABCD If julie makes 18 baskets, how many baskets does Kari make? How many baskets do they make in all? Nosotros _________ jugar a la pelota.A. supisteB. conocemosC. sabemosD. conozcoReset Next what is consumer surplus was it moral for settlers to move in and set up farms and towns? Why/why not? A hot dog and three pickles costs $6.50. Two hot dogs and two pickles costs $7.00. Discuss any five achievements of "Acheampongs" National Redemption Council junta from January to October 1975 in Ghana