File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9999 <program interactive =" activecode" language =" python" >
100100 <code >
101101def main():
102- fahr = int(input("Enter the temperature in F: "))
103- cel = (fahr - 32) * 5.0/9.0
102+ """ Program to convert a temperature from Fahrenheit to Celsius. """
103+ fahr = int(input("Enter the temperature in F: ")) # get the temperature in Fahrenheit
104+ cel = (fahr - 32) * 5.0/9.0 # convert to Celsius
104105 print("the temperature in C is: ", cel)
105106main()
106107 </code > <tests > </tests >
@@ -115,16 +116,19 @@ main()
115116 <listing xml : id =" java-temperature-conversion" >
116117 <program interactive =" activecode" language =" java" >
117118 <code >
118- import java.util.Scanner;
119+ import java.util.Scanner; // import the Scanner class to read input from the user
120+ /**
121+ * Program to convert a temperature from Fahrenheit to Celsius in Java.
122+ */
119123public class TempConv {
120124 public static void main(String[] args) {
121- Double fahr;
125+ Double fahr;
122126 Double cel;
123- Scanner in;
124- in = new Scanner(System.in);
127+ Scanner in; // declare a Scanner variable called in
128+ in = new Scanner(System.in); // create a Scanner object to read input from the user
125129 System.out.println("Enter the temperature in F: ");
126- fahr = in.nextDouble();
127- cel = (fahr - 32) * 5.0/9.0;
130+ fahr = in.nextDouble(); // read the temperature in Fahrenheit from the user
131+ cel = (fahr - 32) * 5.0/9.0; // convert to Celsius
128132 System.out.println("The temperature in C is: " + cel);
129133 }
130134}
You can’t perform that action at this time.
0 commit comments