From 31010c0d6a11525f390d7762e7059b8f98112a73 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Sun, 1 Mar 2026 22:41:55 -0500 Subject: [PATCH 01/18] Ex Date is done. --- ch02/Date.java | 12 ++++++++++++ ch02/DeclareAssign.java | 2 +- ch02/FloatingPoint.java | 4 ---- ch02/PrintingVars.java | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 ch02/Date.java diff --git a/ch02/Date.java b/ch02/Date.java new file mode 100644 index 0000000..85b0395 --- /dev/null +++ b/ch02/Date.java @@ -0,0 +1,12 @@ + +public class Date { + public static void main(String [] args) { + String day = "Monday, "; + int date = 1; + String month = "March "; + int year = 2026; + + System.out.println("American format: " + day + month + date + ", " + year); + System.out.println("European format: " + day + date + " " + month + year); + } +} diff --git a/ch02/DeclareAssign.java b/ch02/DeclareAssign.java index 87a8e02..e701d68 100644 --- a/ch02/DeclareAssign.java +++ b/ch02/DeclareAssign.java @@ -12,7 +12,7 @@ public static void main(String[] args) { hour = 11; // assign the value 11 to hour minute = 59; // set minute to 59 - message = "123"; // legal + message = "123"; // legal // message = 123; // not legal String message2 = "Hello!"; diff --git a/ch02/FloatingPoint.java b/ch02/FloatingPoint.java index b9afa1c..3ce28c3 100644 --- a/ch02/FloatingPoint.java +++ b/ch02/FloatingPoint.java @@ -4,10 +4,6 @@ public static void main(String[] args) { double pi; pi = 3.14159; - double minute3 = 59.0; - System.out.print("Fraction of the hour that has passed: "); - System.out.println(minute3 / 60.0); - double y = 1.0 / 3.0; // correct System.out.println(0.1 * 10); diff --git a/ch02/PrintingVars.java b/ch02/PrintingVars.java index 27a0f08..ed7cb0c 100644 --- a/ch02/PrintingVars.java +++ b/ch02/PrintingVars.java @@ -19,7 +19,7 @@ public static void main(String[] args) { System.out.println(hour * 60 + minute); System.out.print("Fraction of the hour that has passed: "); - System.out.println(minute / 60); + System.out.println(hour * 60); System.out.print("Percent of the hour that has passed: "); System.out.println(minute * 100 / 60); From 0ec562a72f37d1d1aca5db02cd60a220e5d5d0ee Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 4 Mar 2026 09:04:44 -0500 Subject: [PATCH 02/18] Ex 3.2 is done. --- {ch03 => ch02}/Convert.java | 0 {ch03 => ch02}/Echo.java | 0 {ch03 => ch02}/Formatting.java | 0 {ch03 => ch02}/Literals.java | 0 {ch03 => ch02}/ScannerBug.java | 0 ch02/Time.java | 16 ++++++++++++++++ ch03/TempConverter.java | 14 ++++++++++++++ 7 files changed, 30 insertions(+) rename {ch03 => ch02}/Convert.java (100%) rename {ch03 => ch02}/Echo.java (100%) rename {ch03 => ch02}/Formatting.java (100%) rename {ch03 => ch02}/Literals.java (100%) rename {ch03 => ch02}/ScannerBug.java (100%) create mode 100644 ch02/Time.java create mode 100644 ch03/TempConverter.java diff --git a/ch03/Convert.java b/ch02/Convert.java similarity index 100% rename from ch03/Convert.java rename to ch02/Convert.java diff --git a/ch03/Echo.java b/ch02/Echo.java similarity index 100% rename from ch03/Echo.java rename to ch02/Echo.java diff --git a/ch03/Formatting.java b/ch02/Formatting.java similarity index 100% rename from ch03/Formatting.java rename to ch02/Formatting.java diff --git a/ch03/Literals.java b/ch02/Literals.java similarity index 100% rename from ch03/Literals.java rename to ch02/Literals.java diff --git a/ch03/ScannerBug.java b/ch02/ScannerBug.java similarity index 100% rename from ch03/ScannerBug.java rename to ch02/ScannerBug.java diff --git a/ch02/Time.java b/ch02/Time.java new file mode 100644 index 0000000..68b1301 --- /dev/null +++ b/ch02/Time.java @@ -0,0 +1,16 @@ +public class Time { + public static void main(String[] args) { + int hour = 22; + int minute = 44; + int second = 59; + + int secondsSinceMidNight = (22 * 60 * 60) + 59; + System.out.println(secondsSinceMidNight); + + int secondsRemaining = (24 * 60 * 60) - secondsSinceMidNight; + System.out.println(secondsRemaining); + + double percentagePast = (secondsSinceMidNight * 100.0) / (24.0 * 60.0 * 60.0); + System.out.println(percentagePast); + } +} diff --git a/ch03/TempConverter.java b/ch03/TempConverter.java new file mode 100644 index 0000000..149e682 --- /dev/null +++ b/ch03/TempConverter.java @@ -0,0 +1,14 @@ +import java.util.Scanner; + +public class TempConverter { + public static void main(String[] args) { + double Celsius; + Scanner userInput = new Scanner(System.in); + + System.out.print("Enter a temperature in Celsius: "); + Celsius = userInput.nextDouble(); + double Fahrenheit = (Celsius * 9/5) + 32; + + System.out.printf("%.1f C = %.2f F\n", Celsius, Fahrenheit); + } +} From 45de3239c11e9e7184cb1c743319d3b77820a600 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 4 Mar 2026 09:34:35 -0500 Subject: [PATCH 03/18] Ex 3.3 is done. --- ch03/SecondsConverter.java | 21 +++++++++++++++++++++ ch03/TempConverter.java | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 ch03/SecondsConverter.java diff --git a/ch03/SecondsConverter.java b/ch03/SecondsConverter.java new file mode 100644 index 0000000..ec613cb --- /dev/null +++ b/ch03/SecondsConverter.java @@ -0,0 +1,21 @@ +import java.util.Scanner; + +public class SecondsConverter { + public static void main(String[] args) { + int hours; + int minutes; + int seconds; + final int Seconds_In_Hour = 3600; + + Scanner scanner = new Scanner(System.in); + System.out.print("Enter how many seconds you want to calculate: "); + seconds = scanner.nextInt(); + scanner.close(); + + hours = seconds / Seconds_In_Hour; + minutes = (seconds % Seconds_In_Hour) / 60; + seconds = seconds % 60; + + System.out.printf("%d hours, %d minutes, %d seconds\n", hours, minutes, seconds); + } +} diff --git a/ch03/TempConverter.java b/ch03/TempConverter.java index 149e682..a82a12c 100644 --- a/ch03/TempConverter.java +++ b/ch03/TempConverter.java @@ -2,13 +2,13 @@ public class TempConverter { public static void main(String[] args) { - double Celsius; + double celsius; Scanner userInput = new Scanner(System.in); System.out.print("Enter a temperature in Celsius: "); - Celsius = userInput.nextDouble(); - double Fahrenheit = (Celsius * 9/5) + 32; + celsius = userInput.nextDouble(); + double Fahrenheit = (celsius * 9/5) + 32; - System.out.printf("%.1f C = %.2f F\n", Celsius, Fahrenheit); + System.out.printf("%.1f C = %.2f F\n", celsius, Fahrenheit); } } From 1acd5be0f0199b421bc57d3aee367185b923098b Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 4 Mar 2026 10:01:44 -0500 Subject: [PATCH 04/18] Ex 3.4 is done. --- ch03/GuessStarter.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ch03/GuessStarter.java b/ch03/GuessStarter.java index 64984df..df0fd85 100644 --- a/ch03/GuessStarter.java +++ b/ch03/GuessStarter.java @@ -1,4 +1,5 @@ import java.util.Random; +import java.util.Scanner; /** * Starter code for the "Guess My Number" exercise. @@ -9,7 +10,18 @@ public static void main(String[] args) { // pick a random number Random random = new Random(); int number = random.nextInt(100) + 1; - System.out.println(number); + int userGuess; + + System.out.println("I'm thinking of a number between 1 and 100"); + System.out.println("(including both). Can you guess what it is?"); + + Scanner scanner = new Scanner(System.in); + System.out.print("Type a number "); + userGuess = scanner.nextInt(); + + System.out.println("Your guess is: " + userGuess); + System.out.println("The number I was thinking of is: " + number); + System.out.println("You were off by: " + (number - userGuess)); } } From c5c37f008b9ebe8c099a0daeff737e6297fbfbf2 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Mon, 9 Mar 2026 20:34:13 -0400 Subject: [PATCH 05/18] Ex 4.1 is done. --- ch04/DateFromSecondChapter.java | 19 +++++++++++++++++++ ch04/PrintTwice.java | 1 + 2 files changed, 20 insertions(+) create mode 100644 ch04/DateFromSecondChapter.java diff --git a/ch04/DateFromSecondChapter.java b/ch04/DateFromSecondChapter.java new file mode 100644 index 0000000..96a07ab --- /dev/null +++ b/ch04/DateFromSecondChapter.java @@ -0,0 +1,19 @@ +public class DateFromSecondChapter { + public static void printAmerican(String day, int date, String month, int year) { + System.out.println("American format: " + day + ", " + month + " " + date + ", " + year); + } + + public static void printEuropean(String day, int date, String month, int year) { + System.out.println("European format: " + day + " " + date + ", " + month + " " + year); + } + + public static void main(String [] args) { + String day = "Monday"; + int date = 9; + String month = "March"; + int year = 2026; + + printAmerican(day, date, month, year); + printEuropean(day, date, month, year); + } +} diff --git a/ch04/PrintTwice.java b/ch04/PrintTwice.java index 1180417..2515cfb 100644 --- a/ch04/PrintTwice.java +++ b/ch04/PrintTwice.java @@ -1,3 +1,4 @@ + public class PrintTwice { public static void printTwice(String s) { From 5fb02307214105d1ea395a4725cb157fa5f3e17e Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Mon, 9 Mar 2026 20:36:24 -0400 Subject: [PATCH 06/18] Added some changes into the name of the file. --- ...ateFromSecondChapter.java => DateFromSecondChapter_4_1.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ch04/{DateFromSecondChapter.java => DateFromSecondChapter_4_1.java} (93%) diff --git a/ch04/DateFromSecondChapter.java b/ch04/DateFromSecondChapter_4_1.java similarity index 93% rename from ch04/DateFromSecondChapter.java rename to ch04/DateFromSecondChapter_4_1.java index 96a07ab..0dd4f1d 100644 --- a/ch04/DateFromSecondChapter.java +++ b/ch04/DateFromSecondChapter_4_1.java @@ -1,4 +1,4 @@ -public class DateFromSecondChapter { +public class DateFromSecondChapter_4_1 { public static void printAmerican(String day, int date, String month, int year) { System.out.println("American format: " + day + ", " + month + " " + date + ", " + year); } From 85a6a8b28e231fdbe94b9021138f9a3f5dddef81 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Mon, 9 Mar 2026 23:36:11 -0400 Subject: [PATCH 07/18] Ex 4.6 is done. --- ch04/Multadd.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ch04/Multadd.java diff --git a/ch04/Multadd.java b/ch04/Multadd.java new file mode 100644 index 0000000..7598448 --- /dev/null +++ b/ch04/Multadd.java @@ -0,0 +1,22 @@ +public class Multadd { + public static double multadd(double a, double b, double c) { + return a * b + c; + } + + public static double expSum(double x) { + return multadd(x, Math.exp(-x), Math.sqrt(1 - Math.exp(-x))); + } + + public static void main(String[] args) { + System.out.println(multadd(1.0, 2.0, 3.0)); + + double val1 = multadd(Math.sin(Math.PI / 4), 1.0, Math.cos(Math.PI / 4) / 2); + System.out.println(val1); + + double val2 = multadd(1.0, Math.log(10), Math.log(20)); + System.out.println(val2); + + System.out.println(expSum(1.0)); + System.out.println(expSum(2.0)); + } +} From 3ce71bcdc9b544f10e2a07b9c1871b2737219ea6 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 14:03:40 -0400 Subject: [PATCH 08/18] Ex 5.1 is done --- ch05/Ex_5_1.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch05/Ex_5_1.java diff --git a/ch05/Ex_5_1.java b/ch05/Ex_5_1.java new file mode 100644 index 0000000..9890c15 --- /dev/null +++ b/ch05/Ex_5_1.java @@ -0,0 +1,12 @@ +import java.util.Scanner; + +public class Ex_5_1 { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int x = in.nextInt(); + + if (x > 0 && x < 10) { + System.out.println("positive single digit number"); + } + } +} \ No newline at end of file From 2cbf4546fc9c9dec1be0293216a92725a4322bd2 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 14:17:59 -0400 Subject: [PATCH 09/18] Ex 5.2 is done --- ch05/Ex_5_2.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ch05/Ex_5_2.java diff --git a/ch05/Ex_5_2.java b/ch05/Ex_5_2.java new file mode 100644 index 0000000..c1684a2 --- /dev/null +++ b/ch05/Ex_5_2.java @@ -0,0 +1,35 @@ +import java.util.Random; +import java.util.Scanner; + +public class Ex_5_2 { + public static void main(String[] args) { + Random random = new Random(); + int number = random.nextInt(100) + 1; + int userGuess; + int userAttempts = 3; + + System.out.println("I'm thinking of a number between 1 and 100"); + System.out.println("(including both). Can you guess what it is?"); + + while(userAttempts != 0 ) { + Scanner scanner = new Scanner(System.in); + System.out.print("Type a number "); + userGuess = scanner.nextInt(); + + if (userGuess < number) { + System.out.println("Your number is less than the number I'm thinking about"); + userAttempts--; + } else if (userGuess > number) { + System.out.println("Your number is bigger than the number I'm thinking about"); + userAttempts--; + } else { + System.out.println("Congratulations! You guessed right!"); + } + + if (userAttempts == 0) { + System.out.println("I'm sorry you are out of attempts"); + System.out.println("The number I was thinking of is: " + number); + } + } + } +} From 368de02fd0852a2c9cbe5414fb9dd5e65509cff6 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 14:19:45 -0400 Subject: [PATCH 10/18] Made some debugging to break the loop when user guesses the number. --- ch05/Ex_5_2.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ch05/Ex_5_2.java b/ch05/Ex_5_2.java index c1684a2..db9e32c 100644 --- a/ch05/Ex_5_2.java +++ b/ch05/Ex_5_2.java @@ -11,8 +11,9 @@ public static void main(String[] args) { System.out.println("I'm thinking of a number between 1 and 100"); System.out.println("(including both). Can you guess what it is?"); + Scanner scanner = new Scanner(System.in); + while(userAttempts != 0 ) { - Scanner scanner = new Scanner(System.in); System.out.print("Type a number "); userGuess = scanner.nextInt(); @@ -24,6 +25,7 @@ public static void main(String[] args) { userAttempts--; } else { System.out.println("Congratulations! You guessed right!"); + break; } if (userAttempts == 0) { From e9c37ac3b5b18478762036fbed1985e7b6797b8b Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 14:34:14 -0400 Subject: [PATCH 11/18] Fermat's Last Theorem is done. --- ch05/Fermat.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ch05/Fermat.java diff --git a/ch05/Fermat.java b/ch05/Fermat.java new file mode 100644 index 0000000..032eee0 --- /dev/null +++ b/ch05/Fermat.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class Fermat { + public static void main(String[] args) { + int a; + int b; + int c; + int n; + + Scanner in = new Scanner(System.in); + System.out.print("What's your 'a' number? "); + a = in.nextInt(); + System.out.print("What's your 'b' number? "); + b = in.nextInt(); + System.out.print("What's your 'c' number? "); + c = in.nextInt(); + System.out.print("What's your 'n' number? "); + n = in.nextInt(); + + boolean result = Math.pow(a, n) + Math.pow(b, n) == Math.pow(c, n); + + if (n > 2 && result) { + System.out.println("Holy smokes, Fermat was wrong!"); + } else { + System.out.println("No, that doesn't work."); + } + } +} From a46391b750cb5d5c5023757ccc1f66b192629f0f Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 23:37:57 -0400 Subject: [PATCH 12/18] Quadratic is done. --- ch05/Quadratic.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ch05/Quadratic.java diff --git a/ch05/Quadratic.java b/ch05/Quadratic.java new file mode 100644 index 0000000..beb93ef --- /dev/null +++ b/ch05/Quadratic.java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class Quadratic { + public static void main(String[] args) { + int a; + int b; + int c; + + Scanner in = new Scanner(System.in); + + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + a = in.nextInt(); + + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + b = in.nextInt(); + + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + c = in.nextInt(); + + double discriminant = b * b - 4 * a * c; + + if (a == 0) { + System.out.println("The value of 'a' cannot be zero."); + } else if (discriminant < 0) { + System.out.println("No real solutions."); + } else { + double x1 = (-b + Math.sqrt(discriminant)) / (2 * a); + double x2 = (-b - Math.sqrt(discriminant)) / (2 * a); + System.out.println("x1 = " + x1); + System.out.println("x2 = " + x2); + } + } +} From c6ccb86cb0ac3ce599e174997a8d48db847ef7f7 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 11 Mar 2026 23:48:24 -0400 Subject: [PATCH 13/18] Triangle is done --- ch05/Triangle.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ch05/Triangle.java diff --git a/ch05/Triangle.java b/ch05/Triangle.java new file mode 100644 index 0000000..7c8fd1f --- /dev/null +++ b/ch05/Triangle.java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class Triangle { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + int a = in.nextInt(); + if (a <= 0) { + System.err.println("Error: " + a + " is less than or equal to 0."); + return; + } + + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + int b = in.nextInt(); + if (b <= 0) { + System.err.println("Error: " + b + " is less than or equal to 0."); + return; + } + + System.out.print("Enter a number "); + if (!in.hasNextInt()) { + System.out.println("Error: \"" + in.next() + "\" is not a valid integer."); + return; + } + int c = in.nextInt(); + if (c <= 0) { + System.err.println("Error: " + c + " is less than or equal to 0."); + return; + } + + if (a + b > c && a + c > b && b + c > a) { + System.out.println("Yes, these sides can form a triangle."); + } else { + System.out.println("No, these sides cannot form a triangle."); + } + } +} From 39101e5d616eed9e5ce0de8c957114c2a1e9a9a5 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 25 Mar 2026 11:16:03 -0400 Subject: [PATCH 14/18] Ex 6.2 is done. --- ch06/Ex_6_2_SquareRoot.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ch06/Ex_6_2_SquareRoot.java diff --git a/ch06/Ex_6_2_SquareRoot.java b/ch06/Ex_6_2_SquareRoot.java new file mode 100644 index 0000000..f77a458 --- /dev/null +++ b/ch06/Ex_6_2_SquareRoot.java @@ -0,0 +1,21 @@ +public class Ex_6_2_SquareRoot { + public static void main(String[] a) { + System.out.println(squareRoot(9)); // should be ~3.0 + System.out.println(squareRoot(25)); // should be ~5.0 + System.out.println(squareRoot(2)); // should be ~1.4142 + } + + public static double squareRoot(double a) { + double x = a /2; + + while (true) { + double next = (x + a / x) / 2; + + if (Math.abs(next - x) < 0.0001) { + return next; + } + + x = next; + } + } +} From 458ac3d05e7068f29dc2575ef97145edfb00c00d Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Thu, 26 Mar 2026 11:06:02 -0400 Subject: [PATCH 15/18] Doubloon ex is done. --- ch06/isDoubloon.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ch06/isDoubloon.java diff --git a/ch06/isDoubloon.java b/ch06/isDoubloon.java new file mode 100644 index 0000000..a8e013a --- /dev/null +++ b/ch06/isDoubloon.java @@ -0,0 +1,27 @@ +public class isDoubloon { + public static boolean doubloon(String s) { + String lower = s.toLowerCase(); + int[] counts = new int[26]; + + for (int i = 0; i < s.length(); i++) { + char letter = lower.charAt(i); + int index = letter - 'a'; + counts[index]++; + } + + for (int count:counts) { + if (count != 0 && count != 2) { + return false; + } + } + + return true; + } + + public static void main(String[] args) { + System.out.println(doubloon("beriberi")); + System.out.println(doubloon("boob")); + System.out.println(doubloon("tit")); + System.out.println(doubloon("Caucasus")); + } +} From 497575a7107b0119e0fbb29002dfccd367e59f6d Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Mon, 30 Mar 2026 17:07:34 -0400 Subject: [PATCH 16/18] Ex with the Fruits is done. --- ch07/Fruit.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ch07/Fruit.java b/ch07/Fruit.java index 50428c5..8a32c4a 100644 --- a/ch07/Fruit.java +++ b/ch07/Fruit.java @@ -3,9 +3,10 @@ */ public class Fruit { + // Multiplication of all elements public static int banana(int[] a) { - int kiwi = 1; - int i = 0; + int kiwi = 1; // counter + int i = 0; // beginner while (i < a.length) { kiwi = kiwi * a[i]; i++; @@ -13,6 +14,7 @@ public static int banana(int[] a) { return kiwi; } + // Looking for the number in the array; public static int grapefruit(int[] a, int grape) { for (int i = 0; i < a.length; i++) { if (a[i] == grape) { @@ -22,6 +24,7 @@ public static int grapefruit(int[] a, int grape) { return -1; } + // Counting how many number appears in the array that we are looking for; public static int pineapple(int[] a, int apple) { int pear = 0; for (int pine: a) { @@ -31,5 +34,4 @@ public static int pineapple(int[] a, int apple) { } return pear; } - } From 3995168707d9fb893de502ff86b0e20849cdf87f Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Mon, 30 Mar 2026 17:16:05 -0400 Subject: [PATCH 17/18] Ex 2 is done with the MakeDubMus is done. --- ch07/MakeDubMus.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ch07/MakeDubMus.java b/ch07/MakeDubMus.java index 9c7e193..69023d8 100644 --- a/ch07/MakeDubMus.java +++ b/ch07/MakeDubMus.java @@ -11,12 +11,14 @@ public static int[] make(int n) { return a; } + // Multiplies each number to 2; public static void dub(int[] jub) { for (int i = 0; i < jub.length; i++) { - jub[i] *= 2; + jub[i] *= 2; // } } + // Addition of the array zoo; public static int mus(int[] zoo) { int fus = 0; for (int i = 0; i < zoo.length; i++) { @@ -26,9 +28,9 @@ public static int mus(int[] zoo) { } public static void main(String[] args) { - int[] bob = make(5); - dub(bob); - System.out.println(mus(bob)); + int[] bob = make(5); // [1, 2, 3, 4, 5] + dub(bob); // [2, 4, 8, 16, 32] + System.out.println(mus(bob)); // } } From 7dbf9e0788b94d659409eaeaa0291ccee887df10 Mon Sep 17 00:00:00 2001 From: BecksChomoev Date: Wed, 1 Apr 2026 17:14:18 -0400 Subject: [PATCH 18/18] Index of Max is done. --- ch07/indexOfMax.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ch07/indexOfMax.java diff --git a/ch07/indexOfMax.java b/ch07/indexOfMax.java new file mode 100644 index 0000000..cd24b9c --- /dev/null +++ b/ch07/indexOfMax.java @@ -0,0 +1,21 @@ +public class indexOfMax { + public static int indexOfMaxMethod(int[] numbers) { + int result = 0; + int maxVal = numbers[0]; + + for (int i = 1; i < numbers.length; i++) { + if (numbers[i] > maxVal) { + maxVal = numbers[i]; + result = i; + } + } + + return result; + } + + public static void main(String[] args) { + int[] test = {3, 7, 1, 9, 12}; + + System.out.println(indexOfMaxMethod(test)); + } +}