468,509 Members | 1,368 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,509 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!
4 Weeks Ago #1
1 3094
dev7060
430 Expert 256MB
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).
4 Weeks Ago #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
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.