Java code problem with array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Java code problem with array

I just want the results to have space in between them .the results are stacked together public class Program { public static void main(String[] args) { String[][] grids = { {"shoe","clothes","cap"}, {"watch","cream","tshirt"}, {"brace","socks","boxers"}, }; for(int i=0;i<grids.length;i++){ for(int j=0;j<grids[i].length;j++){ System.out.print(grids[i][j]); } System.out.println(); } } }

15th Jan 2022, 11:19 PM
Tony Jadesola
18 Answers
+ 5
Tony Jadesola, it could have been done as you tried, but not println, but print: System.out.print(' '); I advise you to carefully reread the lesson on the topic "Data Output".
16th Jan 2022, 1:49 AM
Solo
Solo - avatar
+ 3
Add two tabs, ("\t"), to the output and not only will you have spaces, but everything will align with columns.
15th Jan 2022, 11:41 PM
Solo
Solo - avatar
+ 3
Tony Jadesola, this course is a negligible part of JAVA. Who knows, it may take you a lifetime to learn JAVA, because while you just started learning, and at this very moment, programmers continue to expand the capabilities of Java. Good luck in your studies! ☺️
16th Jan 2022, 2:21 AM
Solo
Solo - avatar
+ 2
Or, if good enough, try it this way: https://code.sololearn.com/cIkqM8A867p1/?ref=app
16th Jan 2022, 12:01 AM
Coding Cat
Coding Cat - avatar
+ 2
Coding Cat thanks very much that alternative is very much better
16th Jan 2022, 12:04 AM
Tony Jadesola
+ 2
Tony Jadesola, you do not know where you have the data output???😶 System.out.print(grids[i][j]+"\t\t"); Agree, it is much easier to use someone else's code than to think a little and try to write it yourself. ☺️
16th Jan 2022, 1:33 AM
Solo
Solo - avatar
+ 2
ok
17th Jan 2022, 4:13 PM
Clay
+ 1
Tony Jadesola, 🤣🤣🤣 now it is clear why you have not learned to make even spaces between variables. Ask yourself the question: “What is more important for me to complete the course as quickly as possible, or to assimilate the material of this course as best as possible in order to learn how to program?".
16th Jan 2022, 2:13 AM
Solo
Solo - avatar
+ 1
Solo true am still practicing what ave learned cause it looks like I didn't know it well
16th Jan 2022, 2:14 AM
Tony Jadesola
+ 1
how i can be a pro in python?
17th Jan 2022, 4:32 AM
Clay
+ 1
Tony Jadesola in your case it is probably better to use neither println nor print. I suggest printf. You can call System.out.printf("%s ", grids[i][j]) If you want each output on a new line you need to append a linebreak (\n) to each Output.
17th Jan 2022, 8:05 AM
jack
jack - avatar
0
@solo I don't understand where you said I should add two tabs What I did was I added another System.out.println(); Results was like this: Shoeclothescap Watchcreamtshirt Bracesocksboxers As you can see it only gives space to the row(or column anyhow it's called)
16th Jan 2022, 12:02 AM
Tony Jadesola
0
Solo lol 😆 even if I use his code I still want to know how it works that's why I used your own
16th Jan 2022, 1:47 AM
Tony Jadesola
0
@🙂🙂
16th Jan 2022, 1:53 AM
Tony Jadesola
0
@solo I started java yesterday and I finished arrays today .how long do u think will take me to finish java
16th Jan 2022, 1:55 AM
Tony Jadesola
0
Instead of writing println(), use print(" ") to print a space between values.
16th Jan 2022, 7:00 AM
ROHIT SINGH
- 1
Clay lay learn python well and practice it's as simple as that And don't rush like me
17th Jan 2022, 11:33 AM
Tony Jadesola
- 1
System.out.print(grids[I][j]+" ");
17th Jan 2022, 6:25 PM
Subhronil Saha
Subhronil Saha - avatar