java - my logic for printing a loop isnt right. cant get my head aroud this -
//the question (my code after that)
variable n randomly generated integer. output characters '*' , '#' first row contains stars , last 1 number signs. number of stars decreases in each consecutive row. total number of characters in row n , there n + 1 rows.
for example, if n has value 5, program output:
***** ****# ***## **### *#### #####
//my code below!
random r = new random(); int n = r.nextint(5) + 10; system.out.println("n: "+n); while(n>0){ for(int star = n; star>0; star--){ system.out.print("*"); } for(int hash = 0; hash<n; hash++){ system.out.print("#"); } system.out.println(""); //new line n--; }
//my code output - problem: #'s need increase in size 0 rather decrease *'s
**********########## *********######### ********######## *******####### ******###### *****##### ****#### ***### **## *#
just remember line on. no need algorithm talks.
final int n = 4; int linenr = 0; while (n >= linenr) { (int = 1; <= n - linenr; i++) system.out.print("*"); (int j = 1; j <= linenr; j++) system.out.print("#"); system.out.println(); linenr++; }
Comments
Post a Comment