File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments