470,849 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

printing problem

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

but my code is kindof wrong

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!
May 21 '21 #1
1 3895
dev7060
575 Expert 512MB
the expected output is
*_*_*_*_*
*_*_*_*_*
*_*_*_*_*
*_*_*_*_*
*_*_*_*_*

but my code is kindof wrong
Expand|Select|Wrap|Line Numbers
  1. public class RowColumnStarUnderscore {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. int TOTAL_ROWS = 5;
  6. int TOTAL_COLUMNS = 5;
  7.  
  8.  
  9. for(int row=1;row<=TOTAL_ROWS;row++) {
  10.  
  11. for(int col=1; col <=TOTAL_COLUMNS; col++) {
  12.  
  13.  
  14.  
  15. System.out.print("*_");
  16. }
  17.  
  18.  
  19. System.out.println();
  20. }
  21.  
  22. }
  23.  
  24. }
  25.  
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_COLUMNS).
May 22 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Rami | last post: by
5 posts views Thread by rd | last post: by
reply views Thread by Programatix | last post: by
2 posts views Thread by Sukh | last post: by
reply views Thread by Sukh | last post: by
1 post views Thread by benfly08 | last post: by
6 posts views Thread by babaidebnath | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.