Answer to Question #276126 in Java | JSP | JSF for Candy

Question #276126

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) *_*_*_*_*_*_*_*_*_* 


1
Expert's answer
2021-12-10T13:21:48-0500
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS