Java code problem with array | Sololearn: Learn to code for FREE!

+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(); } } }

1/15/2022 11:19:48 PM

Tony Jadesola

18 Answers

New Answer

+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".

+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! โ˜บ๏ธ

+2

Add two tabs, ("\t"), to the output and not only will you have spaces, but everything will align with columns.

+2

Or, if good enough, try it this way: https://code.sololearn.com/cIkqM8A867p1/?ref=app

+2

Coding Cat thanks very much that alternative is very much better

+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. โ˜บ๏ธ

+2

ok

+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?".

+1

Solo true am still practicing what ave learned cause it looks like I didn't know it well

+1

how i can be a pro in python?

+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.

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)

0

Solo lol ๐Ÿ˜† even if I use his code I still want to know how it works that's why I used your own

0

@๐Ÿ™‚๐Ÿ™‚

0

@solo I started java yesterday and I finished arrays today .how long do u think will take me to finish java

0

Instead of writing println(), use print(" ") to print a space between values.

-1

Clay lay learn python well and practice it's as simple as that And don't rush like me

-1

System.out.print(grids[I][j]+" ");