Results 1 to 3 of 3

Thread: Array

  1. #1
    phantom06 is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Array

    How do i store data into a array and then print it out?

    This is the code:

    Java Code:
    int NumOfTracks=Integer.parseInt(JOptionPane.showInputDialog("Enter the number of the tracks"));
    
    for (int i=0; i<NumOfTracks; i++){
                String Newtrack= JOptionPane.showInputDialog("Enter the title of track " + (i+1));
                String Newtime=  JOptionPane.showInputDialog("Enter the duration of the track");
    
            String Tracks[]=new String[NumOfTracks];
    
            for(int t=0;t<Tracks.length;t++){
                Tracks[t]=(Newtrack);
            }
    
             String duration[]=new String[NumOfTracks];
    
            for(int t=0;t<duration.length;t++){
                duration[t]=(Newtime);
            }
    
    
            } //for loop for NumOfTracks
    What is the problem?
    Last edited by phantom06; 02-02-2011 at 09:01 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    For starters you're not using code tags so the code is rather hard to read...

  3. #3
    mastal is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    You have problem with nested for loops. Just try to store data in your first loop ( Tracks[i]=(Newtrack);duration[i]=(Newtime); )

Similar Threads

  1. convert byte array into char array
    By kgkamaraj in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 11:32 AM
  2. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  3. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  4. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •