GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adding code for chapters 1-12 · jayaprabhakar/ThinkJavaCode@c9b1805

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • ch01
    • Goodbye.java
    • Hello.java
  • ch02
    • Variables.java
  • ch03
    • Convert.java
    • Echo.java
    • GuessStarter.java
    • Input.java
    • ScannerBug.java
  • ch04
    • Methods.java
    • NewLine.java
    • PrintTime.java
    • PrintTwice.java
  • ch05
    • Conditional.java
  • ch06
    • Series.java
    • SeriesTest.java
    • ValueMethods.java
  • ch07
    • Tables.java
  • ch08
    • ArrayExamples.java
  • ch09
    • StringsThings.java
  • ch10
    • Max.java
    • PointRect.java
  • ch11
    • Time.java
    • TimeClient.java
  • ch12
    • Card.java
    • CardTable.java
    • Search.java
    • cardset-oxymoron
      • 01c.gif
      • 01d.gif
      • 01h.gif
      • 01s.gif
      • 02c.gif
      • 02d.gif
      • 02h.gif
      • 02s.gif
      • 03c.gif
      • 03d.gif
      • 03h.gif
      • 03s.gif
      • 04c.gif
      • 04d.gif
      • 04h.gif
      • 04s.gif
      • 05c.gif
      • 05d.gif
      • 05h.gif
      • 05s.gif
      • 06c.gif
      • 06d.gif
      • 06h.gif
      • 06s.gif
      • 07c.gif
      • 07d.gif
      • 07h.gif
      • 07s.gif
      • 08c.gif
      • 08d.gif
      • 08h.gif
      • 08s.gif
      • 09c.gif
      • 09d.gif
      • 09h.gif
      • 09s.gif
      • 10c.gif
      • 10d.gif
      • 10h.gif
      • 10s.gif
      • 11c.gif
      • 11d.gif
      • 11h.gif
      • 11s.gif
      • 12c.gif
      • 12d.gif
      • 12h.gif
      • 12s.gif
      • 13c.gif
      • 13d.gif
      • 13h.gif
      • 13s.gif
      • COPYRIGHT
      • back001.gif
      • back101.gif
      • back102.gif
      • back111.gif
      • back191.gif
      • back192.gif
      • bottom01.gif
      • bottom02.gif
      • bottom03.gif
      • bottom04.gif
      • bottom05.gif
      • bottom06.gif
      • bottom07.gif
      • config.txt
      • l01.gif
      • l02.gif
      • l03.gif
      • l04.gif
      • shade.gif
      • shadow00.gif
      • shadow01.gif
      • shadow02.gif
      • shadow03.gif
      • shadow04.gif
      • shadow05.gif
      • shadow06.gif
      • shadow07.gif
      • shadow08.gif
      • shadow09.gif
      • shadow10.gif
      • shadow11.gif
      • shadow12.gif
      • shadow13.gif

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎ch01/Goodbye.java‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Example program that demonstrates print vs println.
3+
*/
4+
public class Goodbye {
5+
6+
/**
7+
* Prints a greeting.
8+
*/
9+
public static void main(String[] args) {
10+
System.out.print("Goodbye, "); // note the space
11+
System.out.println("cruel world");
12+
}
13+
}
Collapse file

‎ch01/Hello.java‎

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Hello {
2+
3+
public static void main(String[] args) {
4+
// generate some simple output
5+
System.out.println("Hello, World!");
6+
}
7+
}
Collapse file

‎ch02/Variables.java‎

Copy file name to clipboard
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Examples from Chapter 2.
3+
*/
4+
public class Variables {
5+
6+
public static void main(String[] args) {
7+
8+
String message;
9+
10+
int x;
11+
12+
String firstName;
13+
String lastName;
14+
int hour, minute;
15+
16+
message = "Hello!"; // give message the value "Hello!"
17+
hour = 10; // assign the value 10 to hour
18+
minute = 59; // set minute to 59
19+
20+
message = "123"; // legal
21+
// message = 123; not legal
22+
23+
String message2 = "Hello!";
24+
int hour2 = 10;
25+
int minute2 = 59;
26+
27+
int a = 5;
28+
int b = a; // a and b are now equal
29+
a = 3; // a and b are no longer equal
30+
31+
String firstLine = "Hello, again!";
32+
System.out.println(firstLine);
33+
34+
System.out.print("The value of firstLine is ");
35+
System.out.println(firstLine);
36+
37+
System.out.print("The current time is ");
38+
System.out.print(hour);
39+
System.out.print(":");
40+
System.out.print(minute);
41+
System.out.println(".");
42+
43+
System.out.print("Number of minutes since midnight: ");
44+
System.out.println(hour * 60 + minute);
45+
46+
47+
System.out.print("Fraction of the hour that has passed: ");
48+
System.out.println(minute / 60);
49+
50+
System.out.print("Percent of the hour that has passed: ");
51+
System.out.println(minute * 100 / 60);
52+
53+
double pi;
54+
pi = 3.14159;
55+
56+
double minute3 = 59.0;
57+
System.out.print("Fraction of the hour that has passed: ");
58+
System.out.println(minute3 / 60.0);
59+
60+
double y = 1.0 / 3.0; // correct
61+
62+
System.out.println(0.1 * 10);
63+
System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1
64+
+ 0.1 + 0.1 + 0.1 + 0.1 + 0.1);
65+
66+
double balance = 123.45; // potential rounding error
67+
int balance2 = 12345; // total number of cents
68+
69+
System.out.println(1 + 2 + "Hello");
70+
// the output is 3Hello
71+
72+
System.out.println("Hello" + 1 + 2);
73+
// the output is Hello12
74+
75+
System.out.println(17 * 3);
76+
System.out.println(hour * 60 + minute);
77+
78+
int percentage;
79+
percentage = (minute * 100) / 60;
80+
81+
hour = minute + 1; // correct
82+
// minute + 1 = hour; syntax error
83+
}
84+
}
Collapse file

‎ch03/Convert.java‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts centimeters to feet and inches.
5+
*/
6+
public class Convert {
7+
8+
public static void main(String[] args) {
9+
double cm;
10+
int feet, inches, remainder;
11+
final double centPerInch = 2.54;
12+
Scanner in = new Scanner(System.in);
13+
14+
// prompt the user and get the value
15+
System.out.print("Exactly how many cm? ");
16+
cm = in.nextDouble();
17+
18+
// convert and output the result
19+
inches = (int) (cm / centPerInch);
20+
feet = inches / 12;
21+
remainder = inches % 12;
22+
System.out.printf("%.2f cm = %d ft, %d in\n",
23+
cm, feet, remainder);
24+
}
25+
}
Collapse file

‎ch03/Echo.java‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Scanner;
2+
3+
public class Echo {
4+
5+
public static void main(String[] args) {
6+
String line;
7+
Scanner in = new Scanner(System.in);
8+
9+
System.out.print("Type something: ");
10+
line = in.nextLine();
11+
System.out.println("You said: " + line);
12+
13+
System.out.print("Type something else: ");
14+
line = in.nextLine();
15+
System.out.println("You also said: " + line);
16+
}
17+
}
Collapse file

‎ch03/GuessStarter.java‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.Random;
2+
3+
/**
4+
* Starter code for the "guess my number" exercise.
5+
*/
6+
public class GuessStarter {
7+
8+
public static void main(String[] args) {
9+
// pick a random number
10+
Random random = new Random();
11+
int number = random.nextInt(100) + 1;
12+
System.out.println(number);
13+
}
14+
}
Collapse file

‎ch03/Input.java‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Examples from Chapter 3.
3+
*/
4+
public class Input {
5+
6+
public static void main(String[] args) {
7+
System.out.println(System.out);
8+
9+
System.out.print(4.0 / 3.0);
10+
System.out.printf("Four thirds = %.3f", 4.0 / 3.0);
11+
12+
double pi = 3.14159;
13+
double x = (int) pi * 20.0;
14+
}
15+
}
Collapse file

‎ch03/ScannerBug.java‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Demonstrates a common problem using Scanner.
5+
*/
6+
public class ScannerBug {
7+
8+
public static void main(String[] args) {
9+
String name;
10+
int age;
11+
Scanner in = new Scanner(System.in);
12+
13+
System.out.print("What is your name? ");
14+
name = in.nextLine();
15+
System.out.print("What is your age? ");
16+
age = in.nextInt();
17+
System.out.printf("Hello %s, age %d\n", name, age);
18+
19+
System.out.print("What is your age? ");
20+
age = in.nextInt();
21+
System.out.print("What is your name? ");
22+
name = in.nextLine();
23+
System.out.printf("Hello %s, age %d\n", name, age);
24+
}
25+
}
Collapse file

‎ch04/Methods.java‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Examples from Chapter 4.
3+
*/
4+
public class Methods {
5+
6+
public static void main(String[] args) {
7+
double root = Math.sqrt(17.0);
8+
double angle = 1.5;
9+
double height = Math.sin(angle);
10+
11+
double degrees = 90;
12+
double angle2 = degrees / 180.0 * Math.PI;
13+
double radians = Math.toRadians(180.0);
14+
double degrees2 = Math.toDegrees(Math.PI);
15+
long x = Math.round(Math.PI * 20.0);
16+
double x2 = Math.cos(angle + Math.PI / 2);
17+
double x3 = Math.exp(Math.log(10.0));
18+
double x4 = Math.pow(2.0, 10.0);
19+
}
20+
}
Collapse file

‎ch04/NewLine.java‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class NewLine {
2+
3+
public static void newLine() {
4+
System.out.println();
5+
}
6+
7+
public static void threeLine() {
8+
newLine();
9+
newLine();
10+
newLine();
11+
}
12+
13+
public static void main(String[] args) {
14+
System.out.println("First line.");
15+
threeLine();
16+
System.out.println("Second line.");
17+
}
18+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.