Learn how to Make Money Online doing freelancing, Affiliate Marketing, Blogging and many more ...
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > Java

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 01-25-2010, 11:03 AM   #1
Newbie Member
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
noirnuit is on a distinguished road

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);
I don't know how to construct the for-loop. Help will be greatly appreciated. Thank you!
noirnuit is offline   Reply With Quote
Old 01-25-2010, 02:32 PM   #2
Contributor
 
Join Date: Apr 2009
Posts: 65
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 2
kiddo is on a distinguished road

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]);
  }
}
I think it works

Last edited by kiddo; 01-25-2010 at 02:44 PM.
kiddo is offline   Reply With Quote
Old 01-25-2010, 09:11 PM   #3
Newbie Member
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
noirnuit is on a distinguished road

Re: Java - printing string array


Yes it DOES work! Thank you sooooo much!!! This has saved me a lot of time
noirnuit is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads / Articles
Thread Thread Starter Forum Replies Last Post
Yahoo packets in VB ! kush_2207 Visual Basic [VB] 11 05-10-2010 02:23 PM
HTML to PDF Converter - The Complete Guide sameer_havakajoka Java 14 04-13-2010 09:31 PM
Need help JAVA programming! ngereja Java 2 10-29-2007 06:55 PM
Strings in Java S k Java 0 10-15-2006 01:20 PM

 

All times are GMT +5.5. The time now is 05:23 AM.