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) {
6
6
System .out .println ("printLogarithm" );
7
7
printLogarithm (3.0 );
8
8
9
+ Scanner in = new Scanner (System .in );
10
+
9
11
System .out .println ("scandouble" );
10
- scanDouble ();
12
+ scanDouble (in );
11
13
12
14
System .out .println ("scandouble2" );
13
- scanDouble2 ();
15
+ scanDouble2 (in );
14
16
}
15
17
16
18
public static void printLogarithm (double x ) {
@@ -22,15 +24,13 @@ public static void printLogarithm(double x) {
22
24
System .out .println ("The log of x is " + result );
23
25
}
24
26
25
- public static void scanDouble () {
26
- Scanner in = new Scanner (System .in );
27
+ public static void scanDouble (Scanner in ) {
27
28
System .out .print ("Enter a number: " );
28
29
double x = in .nextDouble ();
29
30
printLogarithm (x );
30
31
}
31
32
32
- public static void scanDouble2 () {
33
- Scanner in = new Scanner (System .in );
33
+ public static void scanDouble2 (Scanner in ) {
34
34
System .out .print ("Enter a number: " );
35
35
if (!in .hasNextDouble ()) {
36
36
String word = in .next ();
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ public class Tables {
6
6
public static void example () {
7
7
int i = 1 ;
8
8
while (i < 10 ) {
9
- double x = ( double ) i ;
9
+ double x = i ;
10
10
System .out .println (x + " " + Math .log (x ));
11
11
i = i + 1 ;
12
12
}
@@ -15,7 +15,7 @@ public static void example() {
15
15
public static void example2 () {
16
16
int i = 1 ;
17
17
while (i < 10 ) {
18
- double x = ( double ) i ;
18
+ double x = i ;
19
19
System .out .println (x + " " + Math .log (x ) / Math .log (2 ));
20
20
i = i + 1 ;
21
21
}
@@ -25,7 +25,7 @@ public static void example3() {
25
25
final double LOG2 = Math .log (2 );
26
26
int i = 1 ;
27
27
while (i < 100 ) {
28
- double x = ( double ) i ;
28
+ double x = i ;
29
29
System .out .println (x + " " + Math .log (x ) / LOG2 );
30
30
i = i * 2 ;
31
31
}
You can’t perform that action at this time.
0 commit comments