Triangle in java

0

I am new to this java theme, and I want to make the following figure. It should come out like this:

***  
**  
*  

I used the following code:

public class MATRIZ {  
  public static void main(String[] args) {  
    for(int j=0; j<3; j++) {  
      for(int i=0; i<3; i++) {  
        System.out.print( "*" );  
      }  
      System.out.println();  
    }  
  }
}
    
asked by Queve Bel 12.11.2017 в 04:18
source

1 answer

2

The first for must start in reverse order from highest to lowest and in the second to change the limit of variable i to the variable j

public class MATRIZ {  
  public static void main(String[] args) {  
    for(int j=3; j>0; j--) {  
      for(int i=0; i<j; i++) {  
        System.out.print( "*" );  
      }  
      System.out.println();  
    }  
  }
}
    
answered by 12.11.2017 в 04:48