+ 2

Im stuck..Can u pls help me how to create a method for printing a star?;-;

private static void printStars(int amount) { //you can print one star with the command //sout(”*”) //call this command amound times } public static void main(String[] args) { printStars(5); printStars(3); printStars(9); } The program output: ***** *** *********

5th Sep 2018, 10:42 PM
Xanadu2112
Xanadu2112 - avatar
4 Respuestas
+ 1
class Discuss { public static void printStars(int amount) { while(amount!=0) { System.out.print("*"); amount--; } System.out.println(); } public static void main(String[] args) { printStars(5); printStars(3); printStars(9); } }
6th Sep 2018, 2:13 PM
Varun Maheshwari
Varun Maheshwari - avatar
5th Sep 2018, 11:13 PM
NimWing Yuan
NimWing Yuan - avatar
0
When I tried this solution on Netbeans, it just prints infinity amount of * D: public static void main(String[] args) { printStars(5); printStars(3); printStars(9); } public static void printStars(int n) { int i = 1; while (1 <= n) { System.out.println("*"); System.out.println(""); i++; } }
6th Sep 2018, 7:49 AM
Xanadu2112
Xanadu2112 - avatar
0
Dänks!!
7th Sep 2018, 10:20 AM
Xanadu2112
Xanadu2112 - avatar