File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,13 @@ public static void main(String[] args) {
66 System .out .println ("printLogarithm" );
77 printLogarithm (3.0 );
88
9+ Scanner in = new Scanner (System .in );
10+
911 System .out .println ("scandouble" );
10- scanDouble ();
12+ scanDouble (in );
1113
1214 System .out .println ("scandouble2" );
13- scanDouble2 ();
15+ scanDouble2 (in );
1416 }
1517
1618 public static void printLogarithm (double x ) {
@@ -22,15 +24,13 @@ public static void printLogarithm(double x) {
2224 System .out .println ("The log of x is " + result );
2325 }
2426
25- public static void scanDouble () {
26- Scanner in = new Scanner (System .in );
27+ public static void scanDouble (Scanner in ) {
2728 System .out .print ("Enter a number: " );
2829 double x = in .nextDouble ();
2930 printLogarithm (x );
3031 }
3132
32- public static void scanDouble2 () {
33- Scanner in = new Scanner (System .in );
33+ public static void scanDouble2 (Scanner in ) {
3434 System .out .print ("Enter a number: " );
3535 if (!in .hasNextDouble ()) {
3636 String word = in .next ();
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ public class Tables {
66 public static void example () {
77 int i = 1 ;
88 while (i < 10 ) {
9- double x = ( double ) i ;
9+ double x = i ;
1010 System .out .println (x + " " + Math .log (x ));
1111 i = i + 1 ;
1212 }
@@ -15,7 +15,7 @@ public static void example() {
1515 public static void example2 () {
1616 int i = 1 ;
1717 while (i < 10 ) {
18- double x = ( double ) i ;
18+ double x = i ;
1919 System .out .println (x + " " + Math .log (x ) / Math .log (2 ));
2020 i = i + 1 ;
2121 }
@@ -25,7 +25,7 @@ public static void example3() {
2525 final double LOG2 = Math .log (2 );
2626 int i = 1 ;
2727 while (i < 100 ) {
28- double x = ( double ) i ;
28+ double x = i ;
2929 System .out .println (x + " " + Math .log (x ) / LOG2 );
3030 i = i * 2 ;
3131 }
You can’t perform that action at this time.
0 commit comments