59.4k views
0 votes
Write a method called makeStars. The method receives an int parameter that is guaranteed not to be negative. The method returns a String whose length equals the parameter and contains no characters other than asterisks.

User SSEMember
by
2.8k points

1 Answer

7 votes

Answer:

public static String makeStars(int num){

String stars ="";

for(int i =0; i<num; i++){

System.out.print("* ");

}

return stars;

}

Step-by-step explanation:

A complete java program calling the method makeStars and passing an argument of 5 is given below:

public class num1 {

public static String makeStars(int num){

String stars ="";

for(int i =0; i<num; i++){

System.out.print("* ");

}

return stars;

}

public static void main(String[] args) {

System.out.println(makeStars(5));

}

}

User Kyle Vanderstoep
by
3.2k points