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:
  Array named data  indianj at 21:55 on Sunday, September 11, 2005
 

i have an array named data, which contains n integers. i want to print all of the numbers, starting at the data[0]. but if the number 42 occurs, then i want to stop my printing just before the 42(without printing 42). here is most of my for-loop to accomplish my goal:

for (i = 0; i<=42; i++)
System.out.println(data);

what is the correct way to fill in the blank?

  Re: Array named data  crwood at 00:46 on Tuesday, September 13, 2005
 

class PrintTest
{
public static void main(String[] args)
{
int[] data = {
22, 15, 39, 12, 16, 82, 42, 18, 44, 13
};
int stop = 42;
printArrayUpTo(data, stop);
stop = 44;
printArrayUpTo(data, stop);
stop = 99;
printArrayUpTo(data, stop);
}

private static void printArrayUpTo(int[] array, int n)
{
System.out.println("print up to: " + n);
for(int j = 0; j < array.length; j++)
{
if(array[j] == n)
break;
System.out.print(array[j]);
if(j < array.length-1 && array[j+1] != n)
System.out.print(", ");
}
System.out.println();
}
}








CodeToad Experts

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








Recent Forum Threads
•  Date script issues
•  perl script help needed
•  onChange issue
•  perl remote execution
•  Chat application
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007