This is my first attempt at coding. I am completely frustrated and need any help you can give me. I am supposed to take the values in the main method and in the next 2 (these are the ones i am trying to write from scratch) make the values in fahrenheit go from fahrenheit to celsius and then prin them out.

CODE

public class TemperatureConverter {

  public static void main(String[] args) {

    double[] fahrenheit = {-40.0, 0.0, 32.0,
      50.0, 68.0, 75.0, 98.7, 100.0, 212.0};
      convertAndPrint(fahrenheit);
  }
      public static void convertAndPrint(double[] tempArray){
        double i = 0;

        for ( tempArray[0] = 0; i < tempArray.length; tempArray[0]++); 
        i = i - 32 * 5/9;

          conversion(i);

      }

      public static double conversion(double celsius) {

        System.out.println(celsius);
        return celsius;

      }
  }

Recommended Answers

All 3 Replies

Where exactly are you getting the problem and what is it. Also mention in a little detail what you want to achieve.

also please use code tags IE Enter code here

couple of things that i noticed without knowing what problems you were getting:

double i = 0;

for ( tempArray[0] = 0; i < tempArray.length; tempArray[0]++);
i = i - 32 * 5/9;

The 2 biggest issues that i see are :

1. you put a semi at the end of your for loop. nix it.
2. in the for loops conditions you have tempArray[0] = 0 which sets the number at tempArray[0] to 0. So, now when you do your first calculation it would be i = 0 - 32 * 5 / 9 .
3. the incrementing at the end of the for loops conditions, tempArray[0]++ will increment the value of tempArray[0] and not its index.


here is what i think should solve your problem:

public class TemperatureConverter {

public static void main(String[] args) {

double[] fahrenheit = {-40.0, 0.0, 32.0,
50.0, 68.0, 75.0, 98.7, 100.0, 212.0};
convertAndPrint(fahrenheit);
}// end main

public static void convertAndPrint(double[] tempArray){

//notice that i got rid of the double i

for ( int i = 0; i < tempArray.length; i++)
{
double far= tempArray[i]; //a temp var
far = (far - 32) * (5 / 9);
conversion(i);
}//end for
}//end convertAndPrint

public static double conversion(double celsius) {

System.out.println(celsius);
return celsius;

}//end conversion
}//end class

anyway, hope that this helps!! :)

mattwaab;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.