codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  another array question  mrnewbiw at 13:33 on Sunday, October 23, 2005
 

does ayone know code for the following?

1. returns the integer array it is passed with each of the elements tripled.
2. copies the integer array it is passed and returns the copy with each of the elements tripled.
3. returns void but triples all the values of the integer array it is passed.



  Re: another array question  crwood at 16:58 on Sunday, October 23, 2005
 


public class ArrayTest
{
public static void main(String[] args)
{
int[] firstFive = { 1, 2, 3, 4, 5 };
printArray("from getTriples", getTriples(firstFive));
int[] tripled = getTripledCopy(firstFive);
printArray("from getTripledCopy", tripled);
int[] vals = { 2, 3, 4, 5 };
triple(vals);
printArray("from triple", vals);
}

private static int[] getTriples(int[] intArray)
{
for(int j = 0; j < intArray.length; j++)
intArray[j] *= 3;
return intArray;
}

private static int[] getTripledCopy(int[] in)
{
int[] out = new int[in.length];
for(int j = 0; j < out.length; j++)
out[j] = in[j] * 3;
return out;
}

private static void triple(int[] source)
{
for(int j = 0; j < source.length; j++)
source[j] *= 3;
}


private static void printArray(String id, int[] n)
{
System.out.print(id + " = [");
for(int j = 0; j < n.length; j++)
{
System.out.print(n[j]);
if(j < n.length-1)
System.out.print(", ");
}
System.out.print("]\n");
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Why Use Method?
•  Re: Help with a simple program
•  Re: need help with quiz
•  Re: Help with filesystem object & displaying in a table
•  Re: Genetic Algorithm Help
•  Re: How to make an investment calculator
•  Re: line breaks in GUI
•  Re: Graph in Gui...
•  Graph in Gui...


Recent Articles
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net
Creating CSS Buttons


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005