Asked by tusharparik • about 2 months 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
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.
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);
}
}
}
This program initializes the Fahrenheit temperatures with example values. You can modify it to take input from the user or read from a file.
Loading...