Home > front end >  Left Triangle Star Pattern
Left Triangle Star Pattern

Time:03-31

Problem with Left Triangle Star Pattern. Why my code doesn't print as Left Triangle Star Pattern, as i wrote the code as below

public class pattern4 {
    public static void main(String[] args) {
        int row =8;
        for(int i=0;i<row;i  ){
            for(int j=2*(row-i);j>=0;j--){
                System.out.println(" ");
            }
            for(int j=0;j<=i;j  ){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

CodePudding user response:

you must replace println(" ") by print(" ") and update the j :

 public class pattern4 {
    int row =8;
    for(int i=0;i<row;i  ){
        for (int j=row-i; j>1; j--) {
            System.out.print(" ");
        }
        for(int j=0;j<=i;j  ){
            System.out.print("*");
        }
        System.out.println();
    }}}
  • Related