Java How To's
Java How To's
These examples show how to solve common tasks in Java.
Numbers
- Add Two Numbers - Add two numbers and print the result.
- Swap Two Variables - Exchange values between two variables.
- Even or Odd Number - Check if a number is even or odd.
- Positive or Negative - Check if a number is positive or negative.
- Square Root - Find the square root of a number.
- Area of Rectangle - Calculate the area of a rectangle.
- Convert Celsius to Fahrenheit - Convert a temperature from Celsius to Fahrenheit.
- Sum of Digits - Add up the digits of a number.
- Random Number - Generate a random number.
Strings
- Count Words - Count how many words are in a sentence.
- Count Vowels in a String - Count how many vowels are in a string.
- Reverse a String - Reverse the characters in a string.
- Palindrome Check - Check if a string is the same forward and backward.
- Convert String to Array - Split a string into an array of words.
- Remove Whitespace - Delete spaces, tabs, and newlines from a string.
- Count Character Frequency - Count how many times each character appears in a string.
Arrays
- Sum of Array Elements - Add all the elements in an array.
- Find Array Average - Calculate the average value of array elements.
- Sort an Array - Sort array elements.
- Find Smallest Element - Find the lowest value in an array.
- Find Largest Element - Find the largest value in an array.
- Second Largest Array - Find the second largest value in an array.
- Merge Two Arrays - Combine two arrays into one.
- Remove Duplicates Array - Remove duplicates from an array using a Set.
- Shuffle an Array - Randomize the order of array elements.
Algorithms
- Factorial of a Number - Find the factorial of a number.
- Fibonacci Sequence - Print the first 10 Fibonacci numbers.
- Check Prime Number - Check if a number is prime.
Collections
- ArrayList Loop - Loop through an ArrayList.
- HashMap Loop - Loop through a HashMap.
- Loop Through an Enum - Iterate over enum values.