Advertisements
Advertisements
Question
Write a program in Java to store 20 temperatures in °F in a Single Dimensional Array (SDA) and display all the temperatures after converting them into °C.
Hint: `"c"/5 = ("f" - 32)/9`
Answer in Brief
Solution
import java.util.*;
public class AQ2
{ public static void main(String[] jp){
Scanner ob = new Scanner(System.in);
float f[] = new float[2], c[] = new float[2];
System.out.println("Enter the temperatures");
// INPUT AND CONVERSION
for (int = 0; i < f.length; i++)
{f[i} = ob.nextFloat();
c[i] = (float) (5.0 / 9) * (f[i] − 32);
}
// OUTPUT
System.out.println("***Temperatures Converted to Celsius");
for (int j = 0; j < c.length; j++)
System.out.println(c[j]);
}}
shaalaa.com
Is there an error in this question or solution?