Problemas de codificación de Java
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 “Codecademy is the best!”
should output as “Best the is Codecademy!”
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 Codecademy” should return “love.”
To make your program more challenging,
allow for a second numerical input, n,
that results in returning the nth 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 youre 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.
Zealous Zebra