Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01f9e08

Browse filesBrowse files
committed
split ch02
1 parent 44526cc commit 01f9e08
Copy full SHA for 01f9e08

File tree

Expand file treeCollapse file tree

7 files changed

+102
-71
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+102
-71
lines changed
Open diff view settings
Collapse file

‎ch02/DeclareAssign.java‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class DeclareAssign {
2+
3+
public static void main(String[] args) {
4+
String message;
5+
int x;
6+
7+
String firstName;
8+
String lastName;
9+
int hour, minute;
10+
11+
message = "Hello!"; // give message the value "Hello!"
12+
hour = 11; // assign the value 11 to hour
13+
minute = 59; // set minute to 59
14+
15+
message = "123"; // legal
16+
// message = 123; // not legal
17+
18+
String message2 = "Hello!";
19+
int hour2 = 11;
20+
int minute2 = 59;
21+
}
22+
23+
}
Collapse file

‎ch02/FloatingPoint.java‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class FloatingPoint {
2+
3+
public static void main(String[] args) {
4+
double pi;
5+
pi = 3.14159;
6+
7+
double minute3 = 59.0;
8+
System.out.print("Fraction of the hour that has passed: ");
9+
System.out.println(minute3 / 60.0);
10+
11+
double y = 1.0 / 3.0; // correct
12+
13+
System.out.println(0.1 * 10);
14+
System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1
15+
+ 0.1 + 0.1 + 0.1 + 0.1 + 0.1);
16+
17+
double balance = 123.45; // potential rounding error
18+
int balance2 = 12345; // total number of cents
19+
}
20+
21+
}
Collapse file

‎ch02/Hello.java‎

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

‎ch02/MemoryDiagram.java‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class MemoryDiagram {
2+
3+
public static void main(String[] args) {
4+
int a = 5;
5+
int b = a; // a and b are now equal
6+
a = 3; // a and b are no longer equal
7+
int c = 0;
8+
}
9+
10+
}
Collapse file

‎ch02/PrintingVars.java‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class PrintingVars {
2+
3+
public static void main(String[] args) {
4+
String firstLine = "Hello, again!";
5+
System.out.println(firstLine);
6+
7+
System.out.print("The value of firstLine is ");
8+
System.out.println(firstLine);
9+
10+
int hour = 11;
11+
int minute = 59;
12+
System.out.print("The current time is ");
13+
System.out.print(hour);
14+
System.out.print(":");
15+
System.out.print(minute);
16+
System.out.println(".");
17+
18+
System.out.print("Number of minutes since midnight: ");
19+
System.out.println(hour * 60 + minute);
20+
21+
System.out.print("Fraction of the hour that has passed: ");
22+
System.out.println(minute / 60);
23+
24+
System.out.print("Percent of the hour that has passed: ");
25+
System.out.println(minute * 100 / 60);
26+
}
27+
28+
}
Collapse file

‎ch02/StringConcat.java‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class StringConcat {
2+
3+
public static void main(String[] args) {
4+
System.out.println(1 + 2 + "Hello");
5+
// the output is 3Hello
6+
7+
System.out.println("Hello" + 1 + 2);
8+
// the output is Hello12
9+
10+
}
11+
12+
}
Collapse file

‎ch02/Variables.java‎

Copy file name to clipboardExpand all lines: ch02/Variables.java
-71Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.