AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Methods and arrays

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
janicethorne via JavaKB.c
Guest





PostPosted: Thu Apr 20, 2006 4:12 pm    Post subject: Methods and arrays Reply with quote



I have an array that is fed numbers (each on separate lines) by an infile
(File.txt). In a separate class, I needed to create a method to print each
number on the same line and be separated by a space. Is this code the correct
way to reference each separate line of data and print them all together?

double[] data = new double[5];
double ave;

//print all numbers on a line with spaces between them
public static printIt(data) {
for (int index = 0; index < data.length; index++)
outFile.print(data[index]+ " "); }

--
"The man who does not read good books has no advantage over the man who
cannot read them."

Message posted via http://www.javakb.com
Back to top
Bjorn Abelli
Guest





PostPosted: Thu Apr 20, 2006 5:12 pm    Post subject: Re: Methods and arrays Reply with quote



"janicethorne via JavaKB.com" wrote...

Quote:
I have an array that is fed numbers (each on separate lines)
by an infile (File.txt). In a separate class, I needed to
create a method to print each number on the same line and be
separated by a space. Is this code the correct
way to reference each separate line of data and
print them all together?

Almost...

The method signature needs a return type (.e.g.'void'),
and the argument 'data' also needs a type, (e.g. 'double[]').

Quote:
public static printIt(data) {
for (int index = 0; index < data.length; index++)

'outFile' must be declared as a 'static' variable in the class, otherwise
the method can't reach it.

Quote:
outFile.print(data[index]+ " "); }

Apart from those little things, it should work...

// Bjorn A



Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.