I need to figure out a way to print out the alphabet using a 2d array using char[][] alpha = new char[10][5]; .
It would look like this.
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I need to figure out a way to print out the alphabet using a 2d array using char[][] alpha = new char[10][5]; .
It would look like this.
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E
Can you explain why you need an array to print out what you have posted?
A simple loop like this will print it:
for (int i=0; i < 10; i++)
System.out.println("A B C D E");
You can define a 2D array like this:
String[][] twoD = {{"a"}, {"B","C"}};
If you don't understand my answer, don't ignore it, ask a question.
loops to store ‘A’ in the first row, 'B' in the second row, and so on, using the boundaries of [10][5] meaning 10 is the rows and 5 is the columns.
I am already using a 2d array of char [] [] alphabet = new char[10][5];
I assume that those letters go in the first column on each row. What goes in the other four columns on the row?store ‘A’ in the first row, 'B' in the second row
If there are 10 rows then the letters will go from "A" to "J".
If you don't understand my answer, don't ignore it, ask a question.
Yes, I'm just looking for loops that will do that with the 2D array.
That is different than you said:That would be:'A’ in the first row, 'B' in the second row
A
B
C
D
Rows go down, columns go across.
You can define a 2D array in a statement like this:
String[][] twoD = {{"a"}, {"B","C"}};
If you don't understand my answer, don't ignore it, ask a question.
What does it print out? What is wrong with what it prints out?
If you don't understand my answer, don't ignore it, ask a question.
How do the rows go in your array? Are they the first dimension indexed by i?
Try reversing i & j: alpha[j][i]
If you don't understand my answer, don't ignore it, ask a question.
I've tried reversing them but it just gives me an error when I run it.
java.lang.ArrayIndexOutOfBoundsException: 5
at exam2.main(exam2.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.ru nCommand(JavacCompiler.java:271)
Your code is printing out the columns of each row in the array row by row. You need to change the contents of the array is you want to see something different.
Your array has As in all columns of the first row, Bs in all col of second row etc
If you don't understand my answer, don't ignore it, ask a question.