Write a program in java to store 20 temperatures in F in a single dim array (SDA) and display all temperatures after converting them in to C Hint (c/5)=(f-32)/9
Asked by tusharparik • 16 days ago
Write a program in java to store 20 temperatures in F in a single dim array (SDA) and display all temperatures after converting them in to C Hint (c/5)=(f-32)/9
Answers
admin
16 days ago
```html
```
Java Program to Convert Fahrenheit Temperatures to Celsius
Here is a Java program that stores 20 temperatures in Fahrenheit in a single-dimensional array and then displays them after converting them to Celsius.
Java Code
public class TemperatureConverter {
public static void main(String[] args) {
// Array to store 20 temperatures in Fahrenheit
double[] fahrenheitTemperatures = new double[20];
// Example: Initialize with some Fahrenheit values
for (int i = 0; i < fahrenheitTemperatures.length; i++) {
fahrenheitTemperatures[i] = 68 + i * 2; // Example values
}
// Convert and display temperatures
System.out.println("Fahrenheit\tCelsius");
for (double fahrenheit : fahrenheitTemperatures) {
double celsius = (5.0 / 9.0) * (fahrenheit - 32);
System.out.println(fahrenheit + "\t\t" + celsius);
}
}
}
Explanation
- Declare and Initialize the Array:
A double array `fahrenheitTemperatures` is created to store 20 Fahrenheit temperatures. Example values are assigned to it using a loop. - Conversion and Display:
The program iterates through the `fahrenheitTemperatures` array. For each Fahrenheit value, it calculates the equivalent Celsius value using the formula:Celsius = (5.0 / 9.0) * (Fahrenheit - 32)The Fahrenheit and Celsius temperatures are then printed.
This program initializes the Fahrenheit temperatures with example values. You can modify it to take input from the user or read from a file.
Your Answer
Loading...