# Feet to Meters/Meters to Feet- Passing Arrays

Page 1 of 1

## 2 Replies - 1041 Views - Last Post: 14 October 2012 - 05:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=295573&amp;s=31b1090d9c6ec8af446fc5d70e7205ee&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 9
• Joined: 14-October 12

# Feet to Meters/Meters to Feet- Passing Arrays

Posted 14 October 2012 - 09:04 AM

I am very lost in with my assignment. The task is to declare 2 arrays of 10 double numbers, use 1 method to convert 1 - 10 feet into meters and use another method to convert 20 - 30 meters into feet. I need to utilize loops to print the table. I have the following code that I constructed using some examples in my book but it doesn't use and pass the arrays. Help?

```public class Conversion {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

double meter [] = new double [10];
double feet [] = new double [10];

System.out.println("Feet" + "\t\t\t" + "Meters");

//for loop to call foot to meter conversion and print table
for(x=1; x<=10; x++) {
footToMeter(x);
System.out.printf("%7.4f%20.3f" , x, meter);
System.out.println();
}

System.out.println("Meters" + "\t\t\t" + "Feet");

//for loop to call foot method and print out table
for(y = 20; y<=30; y = y+5)
{
feet = meterToFeet(y);
System.out.printf("%7.4f%20.3f" , y, feet);
System.out.println();
}

}

//method to calculate conversion to meters
public static double footToMeter(double [] feet) {
return .3048*feet;
}

//method to calculate conversion to feet
public static double meterToFeet(double [] meter) {
return 3.2808398995*meter;
}

}

```

Is This A Good Question/Topic? 0

## Replies To: Feet to Meters/Meters to Feet- Passing Arrays

### #2 GregBrannon

• D.I.C Lover

Reputation: 2245
• Posts: 5,329
• Joined: 10-September 10

## Re: Feet to Meters/Meters to Feet- Passing Arrays

Posted 14 October 2012 - 09:13 AM

You're getting errors, right? Something like:

```Exception in thread "main" java.lang.Error: Unresolved compilation problems:
x cannot be resolved to a variable
x cannot be resolved to a variable
x cannot be resolved to a variable
x cannot be resolved to a variable
x cannot be resolved to a variable
y cannot be resolved to a variable
y cannot be resolved to a variable
y cannot be resolved to a variable
y cannot be resolved to a variable
y cannot be resolved to a variable
y cannot be resolved to a variable

at Conversion.main(Conversion.java:17)

```

You should post errors when you get them, just as I've done above.

Do you not understand those errors, or did you not see them? In case it's the former, you're using x and y as loop control variables, but you don't declare them. Quite often, that's done:

for ( int x = 1; x <= 10; x++ )

Adding the 'int' before the first x declares and initializes the loop control variable, x. Can you do the same for 'y'?

After you've made those changes, come back with any new problems you need help with.

Reputation: 0
• Posts: 9
• Joined: 14-October 12

## Re: Feet to Meters/Meters to Feet- Passing Arrays

Posted 14 October 2012 - 05:18 PM

I added the int to intialize the x and y variables in the loops and now I get an error on the feetToMeters and metersToFeet variables that says "The method meterToFeet(double[]) in the type Conversion is not applicable for the arguments int".

Also, I am getting an error in both methods for caluclating the conversions that says "the * operator is undefined for the argument type double, double[]".

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }