Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java Coding Problems

You're reading from   Java Coding Problems Improve your Java Programming skills by solving real-world coding challenges

Arrow left icon
Product type Paperback
Published in Sep 2019
Publisher Packt
ISBN-13 9781789801415
Length 816 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Anghel Leonard Anghel Leonard
Author Profile Icon Anghel Leonard
Anghel Leonard
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Strings, Numbers, and Math 2. Objects, Immutability, and Switch Expressions FREE CHAPTER 3. Working with Date and Time 4. Type Inference 5. Arrays, Collections, and Data Structures 6. Java I/O Paths, Files, Buffers, Scanning, and Formatting 7. Java Reflection Classes, Interfaces, Constructors, Methods, and Fields 8. Functional Style Programming - Fundamentals and Design Patterns 9. Functional Style Programming - a Deep Dive 10. Concurrency - Thread Pools, Callables, and Synchronizers 11. Concurrency - Deep Dive 12. Optional 13. The HTTP Client and WebSocket APIs 14. Other Books You May Enjoy

Problems

Use the following problems to test your string manipulation and mathematical corner case programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:

  1. Counting duplicate characters: Write a program that counts duplicate characters from a given string.
  2. Finding the first non-repeated character: Write a program that returns the first non-repeated character from a given string.
  3. Reversing letters and words: Write a program that reverses the letters of each word and a program that reverses the letters of each word and the words themselves.
  4. Checking whether a string contains only digits: Write a program that checks whether the given string contains only digits.
  1. Counting vowels and consonants: Write a program that counts the number of vowels and consonants in a given string. Do this for the English language, which has five vowels (a, e, i, o, and u).
  2. Counting occurrences of a certain character: Write a program that counts the occurrences of a certain character in a given string.
  3. Converting String into int, long, float, or double: Write a program that converts the given String object (representing a number) into int, long, float, or double.
  4. Removing white spaces from a string: Write a program that removes all white spaces from the given string.
  5. Joining multiple strings with a delimiter: Write a program that joins the given strings by the given delimiter.
  6. Generating all permutations: Write a program that generates all of the permutations of a given string.
  7. Checking whether a string is a palindrome: Write a program that determines whether the given string is a palindrome or not.
  8. Removing duplicate characters: Write a program that removes the duplicate characters from the given string.
  9. Removing given characters: Write a program that removes the given character from the given string.
  10. Finding the character with the most appearances: Write a program that finds the character with the most appearances in the given string.
  11. Sorting an array of strings by length: Write a program that sorts by the length of the given array of strings.
  12. Checking that a string contains a substring: Write a program that checks whether the given string contains the given substring.
  13. Counting substring occurrences a string: Write a program that counts the occurrences of a given string in another given string.
  14. Checking whether two strings are anagrams: Write a program that checks whether two strings are anagrams. Consider that an anagram of a string is a permutation of this string by ignoring capitalization and white spaces.
  15. Declaring multiline strings (text blocks): Write a program that declares multiline strings or text blocks.
  16. Concatenating the same string n times: Write a program that concatenates the same string a given number of times.
  17. Removing leading and trailing spaces: Write a program that removes the leading and trailing spaces of the given string.
  1. Finding the longest common prefix: Write a program that finds the longest common prefix of given strings.
  2. Applying indentation: Write several snippets of code to apply indentation to the given text.
  3. Transforming strings: Write several snippets of code to transform a string into another string.
  4. Computing the minimum and maximum of two numbers: Write a program that returns the minimum and maximum of two numbers.
  5. Summing two large int/long numbers and operation overflow: Write a program that sums two large int/long numbers and throws an arithmetic exception in the case of an operation overflow.
  6. String as an unsigned number in the radix: Write a program that parses the given string into an unsigned number (int or long) in the given radix.
  7. Converting into a number by an unsigned conversion: Write a program that converts a given int number into long by an unsigned conversion.
  8. Comparing two unsigned numbers: Write a program that compares the given two numbers as unsigned.
  9. Division and modulo of unsigned values: Write a program that computes the division and modulo of the given unsigned value.
  10. double/float is a finite floating-point value: Write a program that determines whether the given double/float value is a finite floating-point value.
  11. Applying logical AND/OR/XOR to two boolean expressions: Write a program that applies the logical AND/OR/XOR to two boolean expressions.
  12. Converting BigInteger into a primitive type: Write a program that extracts the primitive type value from the given BigInteger.
  13. Converting long into int: Write a program that converts long into int.
  14. Computing the floor of a division and modulus: Write a program that computes the floor division and the floor modulus of the given dividend (x) and divisor (y).
  15. Next floating-point value: Write a program that returns the next floating-point adjacent to the given float/double value in the direction of positive and negative infinity.
  16. Multiplying two large int/long values and operation overflow: Write a program that multiplies two large int/long values and throws an arithmetic exception in the case of operation overflow.
  1. Fused Multiply Add (FMA): Write a program that takes three float/double values (a, b, c) and computes a * b + c in an efficient way.
  2. Compact number formatting: Write a program that formats the number 1,000,000 to 1M (US locale) and to 1 mln (Italian locale). In addition, parse 1M and 1 mln from a string into a number.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime