Here's the portion of my code:
Code:
String[][] courseArray = {{"art", "science"}, {"history", "mathematics"}};
System.out.println ("\n" + "Courses taken this semester: " + courseArray);
![]() |
|
|
#1 |
|
Newbie Member
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Java - printing string array
Hi, I'm trying to figure out how to print a string array in such a way that the output will have 2 rows and 2 columns. Here's the portion of my code: Code:
String[][] courseArray = {{"art", "science"}, {"history", "mathematics"}};
System.out.println ("\n" + "Courses taken this semester: " + courseArray);
|
|
|
|
|
|
#2 |
|
Contributor
Join Date: Apr 2009
Posts: 65
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 2 ![]() |
Re: Java - printing string array
to print two dimension array, we must use loop in loop. Code:
for(condition){
for(condition){
// print array
}
}
Here is the loop example : Code:
String[][] courseArray = new String({"Art","Science"},{"History","Mathematics"});
for(int i=0; i<courseArray.length; i++){
for(int j=0; j<courseArray.length; j++){
System.out.println(courseArray[i][j]);
}
}
Last edited by kiddo; 01-25-2010 at 02:44 PM. |
|
|
|
|
|
#3 |
|
Newbie Member
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 ![]() |
Re: Java - printing string array
Yes it DOES work! Thank you sooooo much!!! This has saved me a lot of time
|
|
|
|
![]() |
|
More
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| Bookmarks | |
|
|
|
|
|||||||||||||||||||||||||||||||