Skip to content

Commit c4e7aa4

Browse files
committed
added comments to code blocks in 3.1
1 parent b9a4cca commit c4e7aa4

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@
9999
<program interactive="activecode" language="python">
100100
<code>
101101
def 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)
105106
main()
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+
*/
119123
public 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
}

0 commit comments

Comments
 (0)