Skip to content

Commit be84536

Browse files
committedMar 13, 2024·
fixing format errors
1 parent 1e24be7 commit be84536

File tree

6 files changed

+61
-49
lines changed

6 files changed

+61
-49
lines changed
 

‎src/com/github/jonathanbirkey/chapter03/Exercise09.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public static void main(String[] args) {
4747
int checksum =
4848
(d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11;
4949
if (checksum == 10) {
50-
System.out.printf("The ISBN-10 number is %d%d%d%d%d%d%d%d%dX\n", d1, d2, d3, d4, d5, d6, d7, d8, d9);
50+
System.out.printf(
51+
"The ISBN-10 number is %d%d%d%d%d%d%d%d%dX\n", d1, d2, d3, d4, d5, d6, d7, d8, d9);
5152
} else {
52-
System.out.printf("The ISBN-10 number is %d%d%d%d%d%d%d%d%d%d\n", d1, d2, d3, d4, d5, d6, d7, d8, d9, checksum);
53+
System.out.printf(
54+
"The ISBN-10 number is %d%d%d%d%d%d%d%d%d%d\n",
55+
d1, d2, d3, d4, d5, d6, d7, d8, d9, checksum);
5356
}
5457
}
5558
}

‎src/com/github/jonathanbirkey/chapter05/Exercise32.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ public static void main(String[] args) {
1515
int lotteryDigit1 = (int) (Math.random() * 10);
1616
int lotteryDigit2 = 0;
1717
do {
18-
lotteryDigit2 = (int) (Math.random() * 10);
19-
}while(lotteryDigit1 == lotteryDigit2);
20-
21-
18+
lotteryDigit2 = (int) (Math.random() * 10);
19+
} while (lotteryDigit1 == lotteryDigit2);
20+
2221
Scanner input = new Scanner(System.in);
2322
System.out.print("Enter your lotter pick (two digits): ");
2423
int guess = input.nextInt();

‎src/com/github/jonathanbirkey/chapter05/Exercise36.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ public static void main(String[] args) {
1414
System.out.print("Enter the first 9 digits of an ISBN as integer: ");
1515
int number = input.nextInt();
1616
input.close();
17-
17+
1818
int tempNumber = number;
1919
int leadingZeroCounter = 0;
2020
int checksum = 0;
2121

2222
for (int i = 9; i > 0; i--) {
23-
int digit = tempNumber % 10;
24-
tempNumber = tempNumber / 10;
25-
if(digit == 0) {
26-
leadingZeroCounter++;
27-
}else {
28-
leadingZeroCounter = 0;
29-
}
30-
checksum += digit * i;
23+
int digit = tempNumber % 10;
24+
tempNumber = tempNumber / 10;
25+
if (digit == 0) {
26+
leadingZeroCounter++;
27+
} else {
28+
leadingZeroCounter = 0;
29+
}
30+
checksum += digit * i;
3131
}
32-
32+
3333
checksum = checksum % 11;
3434
System.out.printf("The ISBN-10 number is ");
35-
35+
3636
if (checksum == 10) {
37-
for(int j = 0; j < leadingZeroCounter; j++) {
38-
System.out.print("0");
39-
}
40-
System.out.printf("%dX", number);
37+
for (int j = 0; j < leadingZeroCounter; j++) {
38+
System.out.print("0");
39+
}
40+
System.out.printf("%dX", number);
4141
} else {
42-
for(int j = 0; j < leadingZeroCounter; j++) {
43-
System.out.print("0");
44-
}
45-
System.out.printf("%d%d", number, checksum);
42+
for (int j = 0; j < leadingZeroCounter; j++) {
43+
System.out.print("0");
44+
}
45+
System.out.printf("%d%d", number, checksum);
4646
}
4747
}
4848
}

‎src/com/github/jonathanbirkey/chapter05/Exercise40.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public static void main(String[] args) {
1212
int coin = 0;
1313
int heads = 0;
1414
int tails = 0;
15-
15+
1616
for (int i = 0; i < 1000000; i++) {
17-
coin = (int)(Math.random()*2);
18-
if(coin == 1) {
19-
heads++;
20-
}else {
21-
tails++;
22-
}
17+
coin = (int) (Math.random() * 2);
18+
if (coin == 1) {
19+
heads++;
20+
} else {
21+
tails++;
22+
}
2323
}
24-
System.out.printf("Heads: %d\nTails: %d",heads, tails);
24+
System.out.printf("Heads: %d\nTails: %d", heads, tails);
2525
}
2626
}

‎src/com/github/jonathanbirkey/chapter05/Exercise41.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@
1818
public class Exercise41 {
1919
public static void main(String[] args) {
2020
Scanner input = new Scanner(System.in);
21-
21+
2222
int max = 0;
2323
int count = 0;
2424
int number = -1;
25-
25+
2626
System.out.print("Enter Numbers: ");
27-
28-
while(number != 0) {
29-
number = input.nextInt();
30-
if(number > max) {
31-
max = number;
32-
count = 1;
33-
} else if(number == max) {
34-
count++;
35-
}
36-
27+
28+
while (number != 0) {
29+
number = input.nextInt();
30+
if (number > max) {
31+
max = number;
32+
count = 1;
33+
} else if (number == max) {
34+
count++;
35+
}
3736
}
3837
input.close();
3938
System.out.printf("The largest number is %d\n", max);

‎src/com/github/jonathanbirkey/chapter05/Exercise44.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
* @author : Jonathan Birkey
33
* @mailto : jonathan.birkey@gmail.com
44
* @created : 28Feb2024
5-
* <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
6-
* 101 to 2100, separated by exactly one space. Also display the number of leap years in this
7-
* period.
5+
* <p>(Computer architecture: bit-level operations) A short value is stored in 16 bits. Write a
6+
* program that prompts the user to enter a short integer and displays the 16 bits for the
7+
* integer. Here are sample runs:
8+
* <p>Enter an integer: 5
9+
* <p>The bits are 0000000000000101
10+
* <p>
11+
* <p>Enter an integer: -5
12+
* <p>The bits are 1111111111111011
813
*/
914
package com.github.jonathanbirkey.chapter05;
1015

16+
import java.util.Scanner;
17+
1118
public class Exercise44 {
1219
public static void main(String[] args) {
13-
// TODO: solve
20+
Scanner input = new Scanner(System.in);
21+
System.out.print("Enter an integer: ");
22+
short decimal = input.nextShort();
23+
input.close();
24+
System.out.printf("The bits are %d", decimal);
1425
}
1526
}

0 commit comments

Comments
 (0)
Please sign in to comment.