printing problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bitty121
    New Member
    • May 2021
    • 2

    printing problem

    the expected output is
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*

    but my code is kindof wrong

    public class RowColumnStarUn derscore {

    public static void main(String[] args) {

    int TOTAL_ROWS = 5;
    int TOTAL_COLUMNS = 5;


    for(int row=1;row<=TOTA L_ROWS;row++) {

    for(int col=1; col <=TOTAL_COLUMNS ; col++) {



    System.out.prin t("*_");
    }


    System.out.prin tln();
    }

    }

    }
    my output is something like this :/

    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_

    please help me to fix this..thank you!
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    the expected output is
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*
    *_*_*_*_*

    but my code is kindof wrong
    Code:
    public class RowColumnStarUnderscore {
    
    public static void main(String[] args) {
    
    int TOTAL_ROWS = 5;
    int TOTAL_COLUMNS = 5;
    
    
    for(int row=1;row<=TOTAL_ROWS;row++) {
    
    for(int col=1; col <=TOTAL_COLUMNS; col++) {
    
    
    
    System.out.print("*_");
    }
    
    
    System.out.println();
    }
    
    }
    
    }
    my output is something like this :/

    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_
    *_*_*_*_*_

    please help me to fix this..thank you!
    One way is to separate out the printing of * and _ and put the latter in a conditional (col!=TOTAL_COL UMNS).

    Comment

    Working...