Write a subroutine named "stars" that will output a line of stars to standard output. (A star is the character "*".) The number of stars should be given as a parameter to the subroutine. Use for loop. For example, the command "stars(10)" would output (6 marks) *_*_*_*_*_*_*_*_*_*
public class Main {
public static void stars(int number) {
for (int i = 0; i < number; i++) {
System.out.print("*");
if (i < number - 1) {
System.out.print("_");
}
}
System.out.println();
}
public static void main(String[] args) {
stars(10);
}
}
Comments
Leave a comment