Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Array Question
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raza




PostPosted: Wed Mar 11, 2009 7:16 pm   Post subject: Array Question

code:
//Complete the following program so that it reverses the order of the values in data, then prints it out.

//In the first version of the program there is only one array and its values are reversed with some fairly tricky programming.

import java.io.* ;

class ReverserVersion1
{

  public static void main ( String[] args )
  {
    int[] data = {1,2,3,4,5,6,7,8,9,10,11,12,13,14};
   
    // reverse the data
    for ( int j=0; j < be careful here; j++)
    {

    }
     
    // write out the new data
    for ( int j=0; j < data.length; j++)
    {

    }

  }
}     



This question has given me something of a headache. You're supposed to solve it without creating another array. The closest I've gotten to solving is data[j]=data[13-j]; which gives me (for obvious reasons) a {14,13,12,11,10,9,8,8,9,10,11,12,13,14} array for an answer. I can't find a way around it, unless I were to find the sum of the array and then subtract each number.. or some other ludicrously time-consuming method, but I'm sure there's a quicker solution.

Help?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Mar 11, 2009 7:26 pm   Post subject: RE:Array Question

but you could create another int variable, no?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raza




PostPosted: Wed Mar 11, 2009 7:37 pm   Post subject: RE:Array Question

Yes, please elaborate.
Tony




PostPosted: Wed Mar 11, 2009 8:17 pm   Post subject: RE:Array Question

would int[] + int give you enough space to reverse the order of values in the int[] ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: