I am working on a program in which I am reading a list of Celsius temperatures from a file, loading them into an array, and eventually loading another array with the corresponding Fahrenheit temperatures for each Celsius temperature.
When attempting to print the fahrArray, rather than displaying actual temperatures which were converted to Fahrenheit to Celsius, I am given this
[D@3d3b10b1>
Here is the code that I have so far.
import java.util.Scanner;
import java.io.*;
public class BonusLab {
public static void main(String[] args) throws IOException {
createdBy();
double[] celArray = loadCelArray();
printArray(celArray);
double[] fahrArray = loadFahrArray(celArray);
} // end main
public static void createdBy() {
System.out.println("Program created by-Beth Tanner");
} // end createdBy
public static double[] loadCelArray() throws IOException {
Scanner fin = new Scanner(new File("weather.txt"));
int x = fin.nextInt();
double[] celArray= new double[x];
for(int i = 0; i < celArray.length; i++)
celArray[i] = fin.nextDouble();
return celArray;
} // end loadCelArray
public static void printArray(double[] celArray) {
for(int i = 0; i < celArray.length; i++)
System.out.print(celArray[i] + " ");
} // end printArray
public static double[] loadFahrArray(double[] celArray) throws IOException {
Scanner fin = new Scanner(new File("weather.txt"));
double celsius =
int x = fin.nextInt();
double[] fahrArray = new double[x];
for(int i = 0; i < fahrArray.length; i++)
fahrArray[i] = (9 / 5) * celsius + 32;
return fahrArray;
} // end loadFahrArray
} // end class
Any help or suggestions would be greatly appreciated.
double celsius =I believe this is typo?double celsius = celArray[i]is the right idea, but you did want to do this more than once, right, since you need to do this for every element ofcelArray? So move it inside theforloop. You will need to add curly braces.fahrArray, but I'm just about positive that you are printing the array instead of the values in the array.