From 9fb1ef4d514055e2e31c56b786ccbd6c384e41a5 Mon Sep 17 00:00:00 2001 From: Chris Mayfield Date: Tue, 27 Dec 2016 12:27:10 -0500 Subject: [PATCH 1/2] sync with 6.1.2 --- ch05/Logarithm.java | 12 ++++++------ ch07/Tables.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ch05/Logarithm.java b/ch05/Logarithm.java index bc21157..5c5986a 100644 --- a/ch05/Logarithm.java +++ b/ch05/Logarithm.java @@ -6,11 +6,13 @@ public static void main(String[] args) { System.out.println("printLogarithm"); printLogarithm(3.0); + Scanner in = new Scanner(System.in); + System.out.println("scandouble"); - scanDouble(); + scanDouble(in); System.out.println("scandouble2"); - scanDouble2(); + scanDouble2(in); } public static void printLogarithm(double x) { @@ -22,15 +24,13 @@ public static void printLogarithm(double x) { System.out.println("The log of x is " + result); } - public static void scanDouble() { - Scanner in = new Scanner(System.in); + public static void scanDouble(Scanner in) { System.out.print("Enter a number: "); double x = in.nextDouble(); printLogarithm(x); } - public static void scanDouble2() { - Scanner in = new Scanner(System.in); + public static void scanDouble2(Scanner in) { System.out.print("Enter a number: "); if (!in.hasNextDouble()) { String word = in.next(); diff --git a/ch07/Tables.java b/ch07/Tables.java index 44e9e62..3e33905 100644 --- a/ch07/Tables.java +++ b/ch07/Tables.java @@ -6,7 +6,7 @@ public class Tables { public static void example() { int i = 1; while (i < 10) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x)); i = i + 1; } @@ -15,7 +15,7 @@ public static void example() { public static void example2() { int i = 1; while (i < 10) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x) / Math.log(2)); i = i + 1; } @@ -25,7 +25,7 @@ public static void example3() { final double LOG2 = Math.log(2); int i = 1; while (i < 100) { - double x = (double) i; + double x = i; System.out.println(x + " " + Math.log(x) / LOG2); i = i * 2; } From 373dd806db8685fdbf7a5fa2e9c8c8eb4028cf3b Mon Sep 17 00:00:00 2001 From: Jayaprabhakar Date: Wed, 15 Nov 2017 03:48:30 -0800 Subject: [PATCH 2/2] Add link to source code hosted on Codiva online java ide Let students directly edit, compile and run java programs on Codiva.io Online Java IDE. This is suitable for beginneers of Java, because they don't have to understand Git, in their early days of learning to code. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 10592d0..0a68248 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Git is a version control system that allows you to keep track of the files that A collection of files under Git's control is called a repository. There are several ways you can work with the code: +* You can edit and run the code on [Codiva online java IDE](https://www.codiva.io/tutorials/thinkjavacode). * You can create a copy of this repository on GitHub by pressing the "Fork" button in the upper right. If you don't already have a GitHub account, you'll need to create one.