loops - How To List Numbers on a Reverse Triangle on Java -


how can print out triangles listed numbers using loops. far manage print this:

1  x 2  x x 3  x x x 4  x x x x 5  x x x x x 

my next assignment same except must print "x" in reverse order user this:

1  x x x x x 2  x x x x 3  x x x 4  x x 5  x 

i manage make code print triangles number not in right place. printout this:

  5  x x x x x  4  x x x x  3  x x x  2  x x  1  x  0 

is there wrong doing? there else need do? here current code:

public class problem4 {     private static scanner input;     public static void main(string[] args)       {         input = new scanner(system.in);         system.out.print("enter number: ");         int n = input.nextint();         (int = n; >= 0; i--)         {             system.out.println("  " + i);             (int j = i; j > 0; j--)             {                 system.out.print(" x");             }         }         system.out.println("");     } } 

modify code this:

import java.util.scanner;  public class problem4 {     private static scanner input;     public static void main(string[] args)       {         input = new scanner(system.in);         system.out.print("enter number: ");         int n = input.nextint();         (int = n; > 0; i--)         {             system.out.print("  " + (n + 1 - i));             (int j = i; j > 0; j--)             {                 system.out.print(" x");             }             system.out.println();         }      } } 

besides that, please follow java naming conventions.

class names should nouns, in mixed case first letter of each internal word capitalized.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -