File tree Expand file tree Collapse file tree 7 files changed +46
-46
lines changed Expand file tree Collapse file tree 7 files changed +46
-46
lines changed Original file line number Diff line number Diff line change 1
1
public class Exercise {
2
-
2
+
3
3
public static void zoop () {
4
4
baffle ();
5
5
System .out .print ("You wugga " );
6
6
baffle ();
7
7
}
8
-
8
+
9
9
public static void main (String [] args ) {
10
10
System .out .print ("No, I " );
11
11
zoop ();
12
12
System .out .print ("I " );
13
13
baffle ();
14
14
}
15
-
15
+
16
16
public static void baffle () {
17
17
System .out .print ("wug" );
18
18
ping ();
19
19
}
20
-
20
+
21
21
public static void ping () {
22
22
System .out .println ("." );
23
23
}
24
-
24
+
25
25
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public static void main(String[] args) {
13
13
double radians = Math .toRadians (180.0 );
14
14
double degrees2 = Math .toDegrees (Math .PI );
15
15
long x = Math .round (Math .PI * 20.0 );
16
-
16
+
17
17
double x2 = Math .cos (angle + Math .PI / 2.0 );
18
18
double x3 = Math .exp (Math .log (10.0 ));
19
19
double x4 = Math .pow (2.0 , 10.0 );
Original file line number Diff line number Diff line change 4
4
* Examples from Chapter 5.
5
5
*/
6
6
public class Conditional {
7
-
7
+
8
8
public static void main (String [] args ) {
9
9
String fruit1 = "Apple" ;
10
10
String fruit2 = "Orange" ;
11
11
System .out .println (fruit1 .equals (fruit2 ));
12
-
12
+
13
13
int x = 17 ;
14
14
int n = 18 ;
15
-
15
+
16
16
if (x > 0 ) {
17
17
System .out .println ("x is positive" );
18
18
}
19
-
19
+
20
20
if (x % 2 == 0 ) {
21
21
System .out .println ("x is even" );
22
22
} else {
23
23
System .out .println ("x is odd" );
24
24
}
25
-
25
+
26
26
if (x > 0 ) {
27
27
System .out .println ("x is positive" );
28
28
} else if (x < 0 ) {
29
29
System .out .println ("x is negative" );
30
30
} else {
31
31
System .out .println ("x is zero" );
32
32
}
33
-
33
+
34
34
if (x == 0 ) {
35
35
System .out .println ("x is zero" );
36
36
} else {
@@ -40,17 +40,17 @@ public static void main(String[] args) {
40
40
System .out .println ("x is negative" );
41
41
}
42
42
}
43
-
43
+
44
44
boolean evenFlag = (n % 2 == 0 ); // true if n is even
45
45
boolean positiveFlag = (x > 0 ); // true if x is positive
46
-
46
+
47
47
if (evenFlag ) {
48
48
System .out .println ("n was even when I checked it" );
49
49
}
50
-
50
+
51
51
if (!evenFlag ) {
52
52
System .out .println ("n was odd when I checked it" );
53
53
}
54
54
}
55
-
55
+
56
56
}
Original file line number Diff line number Diff line change 1
1
public class Exercise {
2
-
2
+
3
3
public static void zoop (String fred , int bob ) {
4
4
System .out .println (fred );
5
5
if (bob == 5 ) {
@@ -8,21 +8,21 @@ public static void zoop(String fred, int bob) {
8
8
System .out .println ("!" );
9
9
}
10
10
}
11
-
11
+
12
12
public static void main (String [] args ) {
13
13
int bizz = 5 ;
14
14
int buzz = 2 ;
15
15
zoop ("just for" , bizz );
16
16
clink (2 * buzz );
17
17
}
18
-
18
+
19
19
public static void clink (int fork ) {
20
20
System .out .print ("It's " );
21
21
zoop ("breakfast " , fork ) ;
22
22
}
23
-
23
+
24
24
public static void ping (String strangStrung ) {
25
25
System .out .println ("any " + strangStrung + "more " );
26
26
}
27
-
27
+
28
28
}
Original file line number Diff line number Diff line change 1
1
import java .util .Scanner ;
2
2
3
3
public class Logarithm {
4
-
4
+
5
5
public static void main (String [] args ) {
6
6
System .out .println ("printLogarithm" );
7
7
printLogarithm (3.0 );
8
-
8
+
9
9
System .out .println ("scandouble" );
10
10
scanDouble ();
11
-
11
+
12
12
System .out .println ("scandouble2" );
13
13
scanDouble2 ();
14
14
}
15
-
15
+
16
16
public static void printLogarithm (double x ) {
17
17
if (x <= 0.0 ) {
18
18
System .err .println ("Error: x must be positive." );
@@ -21,14 +21,14 @@ public static void printLogarithm(double x) {
21
21
double result = Math .log (x );
22
22
System .out .println ("The log of x is " + result );
23
23
}
24
-
24
+
25
25
public static void scanDouble () {
26
26
Scanner in = new Scanner (System .in );
27
27
System .out .print ("Enter a number: " );
28
28
double x = in .nextDouble ();
29
29
printLogarithm (x );
30
30
}
31
-
31
+
32
32
public static void scanDouble2 () {
33
33
Scanner in = new Scanner (System .in );
34
34
System .out .print ("Enter a number: " );
@@ -40,5 +40,5 @@ public static void scanDouble2() {
40
40
double x = in .nextDouble ();
41
41
printLogarithm (x );
42
42
}
43
-
43
+
44
44
}
Original file line number Diff line number Diff line change 1
1
public class Recursion {
2
-
2
+
3
3
public static void main (String [] args ) {
4
4
System .out .println ("countdown" );
5
5
countdown (3 );
6
-
6
+
7
7
System .out .println ("countup" );
8
8
countup (3 );
9
-
9
+
10
10
System .out .println ("newLine" );
11
11
newLine ();
12
-
12
+
13
13
System .out .println ("nLines" );
14
14
nLines (3 );
15
-
15
+
16
16
System .out .println ("threeLine" );
17
17
threeLine ();
18
-
18
+
19
19
System .out .println ("displayBinary" );
20
20
displayBinary (23 );
21
21
System .out .println ();
22
22
}
23
-
23
+
24
24
public static void countdown (int n ) {
25
25
if (n == 0 ) {
26
26
System .out .println ("Blastoff!" );
@@ -29,29 +29,29 @@ public static void countdown(int n) {
29
29
countdown (n - 1 );
30
30
}
31
31
}
32
-
32
+
33
33
public static void newLine () {
34
34
System .out .println ();
35
35
}
36
-
36
+
37
37
public static void threeLine () {
38
38
newLine ();
39
39
newLine ();
40
40
newLine ();
41
41
}
42
-
42
+
43
43
public static void nLines (int n ) {
44
44
if (n > 0 ) {
45
45
System .out .println ();
46
46
nLines (n - 1 );
47
47
}
48
48
}
49
-
49
+
50
50
public static void forever (String s ) {
51
51
System .out .println (s );
52
52
forever (s );
53
53
}
54
-
54
+
55
55
public static void countup (int n ) {
56
56
if (n == 0 ) {
57
57
System .out .println ("Blastoff!" );
@@ -60,12 +60,12 @@ public static void countup(int n) {
60
60
System .out .println (n );
61
61
}
62
62
}
63
-
63
+
64
64
public static void displayBinary (int value ) {
65
65
if (value > 0 ) {
66
66
displayBinary (value / 2 );
67
67
System .out .print (value % 2 );
68
68
}
69
69
}
70
-
70
+
71
71
}
Original file line number Diff line number Diff line change 1
1
public class Exercise {
2
-
2
+
3
3
public static void main (String [] args ) {
4
4
boolean flag1 = isHoopy (202 );
5
5
boolean flag2 = isFrabjuous (202 );
@@ -12,7 +12,7 @@ public static void main(String[] args) {
12
12
System .out .println ("pong!" );
13
13
}
14
14
}
15
-
15
+
16
16
public static boolean isHoopy (int x ) {
17
17
boolean hoopyFlag ;
18
18
if (x % 2 == 0 ) {
@@ -22,7 +22,7 @@ public static boolean isHoopy(int x) {
22
22
}
23
23
return hoopyFlag ;
24
24
}
25
-
25
+
26
26
public static boolean isFrabjuous (int x ) {
27
27
boolean frabjuousFlag ;
28
28
if (x > 0 ) {
@@ -32,5 +32,5 @@ public static boolean isFrabjuous(int x) {
32
32
}
33
33
return frabjuousFlag ;
34
34
}
35
-
35
+
36
36
}
You can’t perform that action at this time.
0 commit comments