JAVA CODING PRACTICE EXERCISES Coding for Beginners (Jj Tam [Tam, Jj])(Z-Library)
,
Java
No Description
327
Views
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
JAVA CODING PRACTICE EXERCISES CODING FOR BEGINNERS JJ TAM
Page
3
JAVA STRING EXERCISES GET THE CHARACTER AT THE GIVEN INDEX WITHIN THE STRING TEST IF A GIVEN STRING CONTAINS THE SPECIFIED SEQUENCE OF CHAR VALUES COMPARE A GIVEN STRING TO THE SPECIFIED STRING BUFFER CHECK WHETHER A GIVEN STRING ENDS WITH THE CONTENTS OF ANOTHER STRING GET THE CONTENTS OF A GIVEN STRING AS A BYTE ARRAY JAVA ARRAY EXERCISES SUM VALUES OF AN ARRAY CALCULATE THE AVERAGE VALUE OF ARRAY ELEMENTS TEST IF AN ARRAY CONTAINS A SPECIFIC VALUE REMOVE A SPECIFIC ELEMENT FROM AN ARRAY INSERT AN ELEMENT INTO AN ARRAY JAVA BASIC EXERCISES SWAP TWO VARIABLES PRINT A FACE FAHRENHEIT TO CELSIUS DEGREE INCHES TO METERS ADDS ALL THE DIGITS PRINT THE NUMBER OF YEARS AND DAYS COMPUTE (BMI) PRINT THE SUM FIND THE GREATEST OF THREE NUMBERS DISPLAY THE MULTIPLICATION TABLE DISPLAY THE PATTERN PRINT A PATTERN LIKE A PYRAMID PRINT THE SUM DIVIDE TWO NUMBERS
Page
4
Java String Exercises Get the character at the given index within the String JAVA CODE public class Exercise1 { public static void main(String[] args) { String str = "Java Exercises!"; System.out.println("Original String = " + str); // Get the character at positions 0 and 10. int index1 = str.charAt(0); int index2 = str.charAt(10);
Page
5
// Print out the results. System.out.println("The character at position 0 is " + (char)index1); System.out.println("The character at position 10 is " + (char)index2); } } OUTPUT Original String = Java Exercises! The character at position 0 is J The character at position 10 is i
Page
6
Test if a given string contains the specified sequence of char values JAVA CODE public class Exercise8 { public static void main(String[] args) { String str1 = "PHP Exercises and Python Exercises"; String str2 = "and"; System.out.println("Original String: " + str1); System.out.println("Specified sequence of char values: " + str2); System.out.println(str1.contains(str2)); } }
Page
7
OUTPUT Original String: PHP Exercises and Python Exercises Specified sequence of char values: and true
Page
8
Compare a given string to the specified string buffer JAVA CODE public class Exercise10 { public static void main(String[] args) { String str1 = "example.com", str2 = "Example.com"; StringBuffer strbuf = new StringBuffer(str1); System.out.println("Comparing "+str1+" and "+strbuf+": " + str1.contentEquals(strbuf)); System.out.println("Comparing "+str2+" and "+strbuf+": " + str2.contentEquals(strbuf)); } } OUTPUT Comparing example.com and example.com: true Comparing Example.com and example.com: false
Page
9
Check whether a given string ends with the contents of another string JAVA CODE public class Exercise12 { public static void main(String[] args) { String str1 = "Python Exercises"; String str2 = "Python Exercise"; // The String to check the above two Strings to see // if they end with this value (se). String end_str = "se"; // Check first two Strings end with end_str boolean ends1 = str1.endsWith(end_str); boolean ends2 = str2.endsWith(end_str);
Page
10
// Display the results of the endsWith calls. System.out.println("\"" + str1 + "\" ends with " + "\"" + end_str + "\"? " + ends1); System.out.println("\"" + str2 + "\" ends with " + "\"" + end_str + "\"? " + ends2); } } OUTPUT "Python Exercises" ends with "se"? false "Python Exercise" ends with "se"? true
Page
11
Get the contents of a given string as a byte array JAVA CODE import java.util.Calendar; public class Exercise16 { public static void main(String[] args) { String str = "This is a sample String."; // Copy the contents of the String to a byte array. byte[] byte_arr = str.getBytes(); // Create a new String using the contents of the byte array. String new_str = new String(byte_arr); // Display the contents of the byte array. System.out.println("\nThe new String equals " + new_str + "\n"); } } OUTPUT The new String equals This is a sample String.
Page
12
Java Array Exercises Sum values of an array JAVA CODE public class Exercise2 { public static void main(String[] args) { int my_array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = 0; for (int i : my_array) sum += i; System.out.println("The sum is " + sum); } } OUTPUT
Page
13
The sum is 55
Page
14
Calculate the average value of array elements JAVA CODE public class Exercise4 { public static void main(String[] args) { int[] numbers = new int[]{20, 30, 25, 35, -16, 60, -100}; //calculate sum of all array elements int sum = 0; for(int i=0; i < numbers.length ; i++) sum = sum + numbers[i]; //calculate average value double average = sum / numbers.length;
Page
15
System.out.println("Average value of the array elements is : " + average); } } OUTPUT Average value of the array elements is : 7.0
Page
16
Test if an array contains a specific value JAVA CODE public class Exercise5 { public static boolean contains(int[] arr, int item) { for (int n : arr) { if (item == n) { return true; } } return false; }
Page
17
public static void main(String[] args) { int[] my_array1 = { 1789, 2035, 1899, 1456, 2013, 1458, 2458, 1254, 1472, 2365, 1456, 2265, 1457, 2456}; System.out.println(contains(my_array1, 2013)); System.out.println(contains(my_array1, 2015)); } } OUTPUT true false
Page
18
Remove a specific element from an array JAVA CODE import java.util.Arrays; public class Exercise7 { public static void main(String[] args) { int[] my_array = {25, 14, 56, 15, 36, 56, 77, 18, 29, 49}; System.out.println("Original Array : "+Arrays.toString(my_array)); // Remove the second element (index->1, value->14) of the array int removeIndex = 1;
Page
19
for(int i = removeIndex; i < my_array.length -1; i++){ my_array[i] = my_array[i + 1]; } // We cannot alter the size of an array , after the removal, the last and second last element in the array will exist twice System.out.println("After removing the second element: "+Arrays.toString(my_array)); } } OUTPUT Original Array : [25, 14, 56, 15, 36, 56, 77, 18, 29, 49] After removing the second element: [25, 56, 15, 36, 56, 77, 18, 29, 49, 49]
Page
20
Insert an element into an array JAVA CODE import java.util.Arrays; public class Exercise9 { public static void main(String[] args) { int[] my_array = {25, 14, 56, 15, 36, 56, 77, 18, 29, 49}; // Insert an element in 3rd position of the array (index->2, value->5) int Index_position = 2; int newValue = 5; System.out.println("Original Array : "+Arrays.toString(my_array));
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
【One-Line Pitch】
A hands-on Java workbook that teaches absolute beginners by making them type, run, and inspect short programs, from string and array manipulation to basic math and console patterns. Best for self-learners who want immediate, visible output rather than theory.
【Book Arc】
- **Opening (~0%–13%)**: The table of contents doubles as a syllabus — string exercises, array exercises, and basic exercises — establishing the book's three-part structure and its exercise-first, no-theory approach.
- **Early (~13%–25%)**: String manipulation drills: fetching characters by index, checking substring containment, comparing a String to a StringBuffer, testing suffixes, and converting strings to byte arrays.
- **Early–Middle (~25%–50%)**: Array fundamentals: summing and averaging elements, searching for a value, and the trickier mechanics of removing and inserting elements by shifting values in place.
- **Middle (~50%–75%)**: Basic exercises shift to user input via Scanner: swapping variables, printing ASCII art, unit conversions (Fahrenheit to Celsius, inches to meters), digit summing, minutes-to-years/days, and BMI.
- **Late (~75%–88%)**: Arithmetic and logic practice: computing sum, difference, product, average, distance, max and min; finding the greatest of three numbers with nested conditionals; and generating multiplication tables.
- **Ending (~88%–100%)**: Nested-loop pattern printing — right-angle number triangles and centered pyramids — closing with simple sum and division programs that reinforce input, arithmetic, and output formatting.
【Key Takeaways】
- **Every concept arrives as a runnable program** (Opening): the book teaches through complete code listings paired with expected output, so you learn by observing behavior rather than reading explanations.
- **Strings are treated as a toolkit to be drilled** (Early): charAt, contains, contentEquals, endsWith, and getBytes are each isolated in their own exercise, building familiarity with the standard API one method at a time.
- **Arrays teach mutation, not just traversal** (Early–Middle): the remove and insert exercises expose the fixed-size constraint of Java arrays and the manual shifting required to work around it.
- **Scanner-based input is the recurring bridge to interactivity** (Middle): most basic exercises read from the console, accustoming beginners to input handling, type conversion, and formatted output.
- **Small math problems hide real programming lessons** (Middle–Late): digit extraction via modulo and division, unit conversion constants, and BMI formulas double as practice in integer vs. double arithmetic.
- **Conditionals and loops are learned through visual feedback** (Late–Ending): greatest-of-three logic and nested-loop patterns make control flow tangible because the output is immediately verifiable.
- **Output comparison is the built-in feedback loop** (throughout): each exercise supplies expected results, letting readers self-check without an instructor.
【Reading Tips】
- **Type the code, don't read it.** The value here is muscle memory and observing actual output; copying from the page defeats the purpose.
- **Predict the output before running.** Especially for the array-shifting and pattern exercises, guessing first exposes gaps in your mental model.
- **Deep-read the array remove/insert section** (~38%–50%): it is the one place the book confronts a genuine Java limitation, and it repays careful attention.
- **Skim the conversions and BMI exercises** if you already know arithmetic in Java; they are formula practice more than new concepts.
- **Treat the pattern-printing chapter as loop training**, not art — the pyramid exercise is the best nested-loop workout in the book.
【Coverage Limits】
This guide is based on stratified excerpts covering the table of contents and representative exercises across all three sections; the excerpts do not cover any prose explanations, so it is unclear whether the book contains narrative instruction beyond code and output. No chapter titles beyond the three exercise categories are confirmed.
Passage locations
Excerpt 1
书名: JAVA CODING PRACTICE EXERCISES Coding for Beginners (Jj Tam [Tam, Jj]) (Z-Library) 作者: Jj Tam [Tam, Jj] JAVA CODING PRACTICE EXERCISES CODI...
View in text
Page 10
System.out.println("\"" + str2 + "\" ends with " + "\"" + end_str + "\"? " + ends2); } OUTPUT "Python Exercises" ends with "se"? false ...
View in text
Excerpt 3
f (item == n) { return true; return false; public static void main(String[] args) { int[] my_array1 = { 1789, 2035...
View in text
Excerpt 4
nt("Input a value for inch: "); double inch = input.nextDouble(); double meters = inch * 0.0254; System.out.println(inch + " inch is...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay