using java Arrays Create a Class to practice with Arrays Cal

using java

(Arrays) Create a Class to practice with Arrays. Call your class “Convert”, and store it in a file called “Convert.java”. In this class you will create the 2 arrays of data. One array to store Fahrenheit temperatures and one to store Celsius temperatures. The first array will store the Fahrenheit temps from 0 to 500, in increments of 25. That is 0, 25, 50, 75…etc. The second array will store the equivalent celsius temp. Use a loop to fill the 2 arrays and a second loop to print out the 2 arrays in a table format. You can do all this code in main() if you want.

Solution

Convert.java

import java.text.DecimalFormat;


public class Convert {

  
   public static void main(String[] args) {
       double f[] = new double[21];
       double c[] = new double[21];
       double celsius;
       for(int i=0, j =0; i<f.length; i++,j+=25){
           f[i] = j;
           celsius = ((j - 32) * 5)/(double)9;
           c[i] = celsius;
       }
       DecimalFormat df = new DecimalFormat(\"0.00\");
       System.out.println(\"Fahrenheit\\tCelsius\");
       for(int i=0; i<f.length; i++){
           System.out.println(f[i]+\"\\t\"+df.format(c[i]));
       }
   }

}

Output:

Fahrenheit   Celsius
0.0   -17.78
25.0   -3.89
50.0   10.00
75.0   23.89
100.0   37.78
125.0   51.67
150.0   65.56
175.0   79.44
200.0   93.33
225.0   107.22
250.0   121.11
275.0   135.00
300.0   148.89
325.0   162.78
350.0   176.67
375.0   190.56
400.0   204.44
425.0   218.33
450.0   232.22
475.0   246.11
500.0   260.00

using java (Arrays) Create a Class to practice with Arrays. Call your class “Convert”, and store it in a file called “Convert.java”. In this class you will crea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site