[ad_1]

If you’re starting a career as a Front-End Developer, Full-Stack Developer, or Computer Scientist, then you’ve probably started learning Java. Maybe you’ve started with an online course, which is a great way to build a solid programming foundation. Once you’re familiar with the basics, try putting your Java skills to the test with some practical exercises to build on your knowledge.

One of the best features of Java is its flexibility. You may find that there are multiple ways to solve the same challenge. In fact, if you’re learning Java with a friend, try these challenges together and learn from each other by comparing your results.

If you get stuck, try thinking through the problem using pseudocode or a general description of the programming steps you’d use to solve the problem. Pseudocode is helpful because it lets you work through programming challenges without having to worry about the specific syntax of a programming language (you can worry about that later).

Below are 10 Java code challenges for beginners. The first five challenges are with strings, while the last five challenges involve numerical inputs. Let’s get started!

**10 Java code challenges to practice your new skills**

**1. Word reversal**

For this challenge, the input is a string of words, and the output should be the words in reverse but with the letters in the original order. For example, the string “Dog bites man” should output as “man bites Dog.”

After you’ve solved this challenge, try adding sentence capitalization and punctuation to your code. So, the string “Skillacademy is the best!” should output as “Best the is Skillacademy!”

**2. Find the word**

Starting with an input string of words, find the second-to-last word of the string. For example, an input of “I love Skillacademy” should return “love.”

To make your program more challenging, allow for a second numerical input, *n*, that results in returning the *n*th word of a string. So, for the string “I can program in Java” and *n* = 3, the output should be the third word, “program.”

**3. Word search**

For a given input string, return a Boolean TRUE if the string starts with a given input word. So, for an input string of “hello world” and input word “hello,” the program should return TRUE.

For a more advanced word searcher, create a program that returns the number of times a word appears in an input string. For example, given an input word “new” and an input string “I’m the new newt,” the program should return a value of 2.

**4. Anagrams**

Two words are anagrams if they contain the same letters but in a different order. Here are a few examples of anagram pairs:

- “listen” and “silent”
- “binary” and “brainy”
- “Paris” and “pairs”

For a given input of two strings, return a Boolean TRUE if the two strings are anagrams.

As an added challenge, for a given array of strings, return separate lists that group anagrams together. For example, the input {“tar,” “rat,” “art,” “meats,” “steam”}, the output should look something like {[“tar,” “rat,” “art”], [“meats,” “steam”]}.

**5. Pangrams**

A pangram is a sentence that contains all 26 letters of the English alphabet. One of the most well-known examples of a pangram is, “The quick brown fox jumps over the lazy dog.” Create a pangram checker that returns a Boolean TRUE if an input string is a pangram and FALSE if it isn’t.

For an added pangram challenge, create a perfect pangram checker. A perfect pangram is a sentence that uses each letter of the alphabet only once, such as, “Mr. Jock, TV quiz Ph.D., bags few lynx.”

**6. Number reversal**

This one is a technical interview favorite. For a given input number, return the number in reverse. So, an input of 3956 should return 6593.

If you’re ready for a bigger challenge, reverse a decimal number. The decimal point should stay in the same place. So, the number 193.56 should output 653.91.

**7. Armstrong numbers**

An Armstrong number is a whole number that’s equal to the sum of its digits raised to the power of the total number of digits. For example, 153 is an Armstrong number because there are three digits, and 153 = 13 + 53 + 33. The four-digit number 8208 is also an Armstrong number, as 8208 = 84 + 24 + 04 + 84.

Create an Armstrong number checker that returns a Boolean TRUE if the input number is an Armstrong number. Hint: to extract each digit from a given number, try using the remainder/modulo operator.

If you’re looking for something a little more challenging, create an Armstrong number calculator that returns all Armstrong numbers between 0 and the input number.

**8. Product maximizer**

For a given input array of numbers, find the two that result in the largest product. The output should include the two numbers in the array along with their product.

As an extra challenge, use an input of two arrays of numbers and find two numbers — one from each input array — that results in the largest product.

**9. Prime number checker**

A prime number is any whole number greater than 1 whose only factors are 1 and itself. For example, 7 is a prime number because it’s only divisible by 1 and 7.

Create a function that returns TRUE if an input number is prime. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, and 19.

For a slightly harder challenge, create a prime number calculator that outputs all prime numbers between 2 and the input number.

**10. Prime factorization**

The prime factors of a number are all of the integers below that number that are divisible into the number as well as 1. For example, the prime factors of 12 are 1,2,3,4,6, and 12.

Create a prime factorization calculator that returns the prime factors of any number between 2 and 100. If you’re looking for a more advanced version of this challenge, use exercise 9 to create a prime factorization calculator for any number. Hint: think about using square roots to cut your work in half.

**Advancing your career with Java**

Along with being a fun, low-stress way to test your knowledge of a programming language, code challenges play an important role in helping you prepare for the interview process. If you’re pursuing a career where knowledge of Java is expected, then you’ll be asked to complete a Java-based coding test, as well as other questions related to Java. And, the best way to prepare for that test is to practice code challenges like these.

To find more opportunities to practice, take a look at our other Java courses, including our popular Java for Programmers course.

[ad_2]