Question
public class TempLoops { public static void main(String[] args) { int Fahrenheit; double Celsius; // 1. for System.out.println(FahrenheitttCelsius); for (Fahrenheit = 0; Fahrenheit
public class TempLoops {
public static void main(String[] args) { int Fahrenheit; double Celsius; // 1. for System.out.println("Fahrenheit\t\tCelsius"); for (Fahrenheit = 0; Fahrenheit <= 300; Fahrenheit += 20) { Celsius = (Fahrenheit - 32.0) * (5.0 / 9.0); System.out.printf("\t%d\t\t\t%.1f ", Fahrenheit, Celsius); }
// 2. while System.out.println("Fahrenheit\t\tCelsius"); Fahrenheit = 0; while (Fahrenheit <= 300) { Celsius = (Fahrenheit - 32.0) * (5.0 / 9.0); System.out.printf("\t%d\t\t\t%.1f ", Fahrenheit, Celsius); Fahrenheit += 20; }
// 3. do-while System.out.println("Fahrenheit\t\tCelsius"); Fahrenheit = 0; do { Celsius = (Fahrenheit - 32.0) * (5.0 / 9.0); System.out.printf("\t%d\t\t\t%.1f ", Fahrenheit, Celsius); Fahrenheit += 20; } while (Fahrenheit <= 300); }//end main }//end class
Modify this Fahr/Celsius program. This time, as you go through the loop, instead of printing the Fahrenheit and Celsius data out, store the values in 2 arrays; one array for Fahrenheit and one array for Celsius. After the first loop that stores the data completes, write another loop that will print out the 2 arrays of data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started