Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EGR 140: Computer Programming Homework #4: Assigned: Wednesday, 4 October 2017 D

ID: 3589496 • Letter: E

Question


EGR 140: Computer Programming Homework #4: Assigned: Wednesday, 4 October 2017 Due: Wednesday, 11 October 2017 (beginning of class) Points: 8 Do not turn in homework via Canvas. Type out the answers and turn in on 8.5x11 paper in class on the due date. Write a Java program to do the following: .Declare an array of 8 data values and set the data values to the following numbers: 4,-6, 7, 23, -1, 12, 17, 5. (A ssume the data values correspond to temperatures in Cel sius.) For example: double [I temps (4,-6, 7, 23,-1 1217, 5) Use an "enhanced for" loop to display the contents of the (original) array. . Use a loop to convert the temperatures from Celsius to Fahrenheit. That is, change the values in the array from to. (Do not make a separate array. Overwrite the elements in the original array) Display the Fahrenheit temperature values.

Explanation / Answer

import java.io.*;


public class DemoEnhanced{
    public static void main(String[] args){

       double[] temps = {4,-6,7,23,-1,12,17,5};

       for (double t :temps)
           System.out.print(t + " ");
       System.out.println();
       for(int i = 0; i<temps.length; i++){
          temps[i] = temps[i] * (9/5) + 32;
       }
       System.out.println("In Farenheit:");
       for (double t :temps)
           System.out.print(t);
       System.out.println();
    }
}