You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/ch3_javadatatypes.ptx
+38-37Lines changed: 38 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -231,43 +231,6 @@ public class TempConv {
231
231
So, what exactly does the import statement do? What it does is tell the compiler that we are going to use a shortened version of the class’s name. In this example we are going to use the class <c>java.util.Scanner</c> but we can refer to it as just <c>Scanner</c>. We could use the <c>java.util.Scanner</c> class without any problem and without any import statement, provided that we always referred to it by its full name. As an experiment, you may want to try this yourself. Remove the import statement and change the string Scanner to <c>java.util.Scanner</c> in the rest of the code. The program should still compile and run.
System.out.print("Enter distance in kilometers: ");
260
-
kilometers = input.nextDouble();
261
-
miles = kilometers * 0.621;
262
-
System.out.println(kilometers + " kilometers is equal to " + miles + " miles.");
263
-
}
264
-
}
265
-
</input>
266
-
</program>
267
-
</solution>
268
-
</exercise>
269
-
270
-
271
234
</subsection>
272
235
273
236
@@ -317,6 +280,44 @@ public class KmToMiles {
317
280
<p>
318
281
The general rule in Java is that you must decide what kind of an object your variable is going to reference and then you must declare that variable before you use it. In our temperature converter, the calculation <c>(fahr - 32) * 5.0/9.0</c> works correctly because 5.0 and 9.0 are treated as double values, preventing the integer division that would occur if we had written <c>5/9</c>, which would result in 0.
0 commit comments