s3a
January 19th, 2010, 10:47 PM
I am reading a little bit ahead before my next semester of school starts and I do not understand why I can't solve the following problem taken from my text book:
Checkpoint 8.13: Look at the following method header: public static void myMethod(double[] array)
Here is an array declaration: double[] numbers = new double[100];
Write a statement that passes the numbers array to the myMethod method.
Here is my code:
import java.util.Scanner;
public class arraysandarraylistcheckpoint8
{
public static void main (String[] args)
{
// 8.13
double[] numbers = new double[100];
myMethod(numbers);
public static void myMethod(double[] array)
{
for(int index = 0; index < array.length; index++)
{
array[index] = 5;
}
}
}
}
I wrote some unnecessary code such as the for loop with the array[index] = 5; but isn't the only requirement to solve that problem simply a matter of calling the myMethod method by "giving" an array (myMethod(numbers);)? Also, what's the proper term for "giving?"
Any input would be greatly appreciated!
Thanks in advance!
P.S.
The error message is as follows:
deniz@debian:~$ cd '/media/PROGRAMMING/Programming'
deniz@debian:/media/PROGRAMMING/Programming$ javac arraysandarraylistcheckpoint8.java
arraysandarraylistcheckpoint8.java:53: illegal start of expression
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: illegal start of expression
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: ';' expected
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: '.class' expected
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: ';' expected
public static void myMethod(double[] array)
^
5 errors
deniz@debian:/media/PROGRAMMING/Programming$
Checkpoint 8.13: Look at the following method header: public static void myMethod(double[] array)
Here is an array declaration: double[] numbers = new double[100];
Write a statement that passes the numbers array to the myMethod method.
Here is my code:
import java.util.Scanner;
public class arraysandarraylistcheckpoint8
{
public static void main (String[] args)
{
// 8.13
double[] numbers = new double[100];
myMethod(numbers);
public static void myMethod(double[] array)
{
for(int index = 0; index < array.length; index++)
{
array[index] = 5;
}
}
}
}
I wrote some unnecessary code such as the for loop with the array[index] = 5; but isn't the only requirement to solve that problem simply a matter of calling the myMethod method by "giving" an array (myMethod(numbers);)? Also, what's the proper term for "giving?"
Any input would be greatly appreciated!
Thanks in advance!
P.S.
The error message is as follows:
deniz@debian:~$ cd '/media/PROGRAMMING/Programming'
deniz@debian:/media/PROGRAMMING/Programming$ javac arraysandarraylistcheckpoint8.java
arraysandarraylistcheckpoint8.java:53: illegal start of expression
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: illegal start of expression
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: ';' expected
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: '.class' expected
public static void myMethod(double[] array)
^
arraysandarraylistcheckpoint8.java:53: ';' expected
public static void myMethod(double[] array)
^
5 errors
deniz@debian:/media/PROGRAMMING/Programming$