bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java

Java

Java How To's

Java How To's focused on Java How To's and related concepts.

Lesson 1

Java How To's

These examples show how to solve common tasks in Java.

Read lesson →Loading…
Lesson 2

Java How To Add Two Numbers

Explanation: We create two integer variables ( x and y ) and assign them values. The expression x + y is stored in the variable sum . Finally, we print the result with System.out.println() .

Read lesson →Loading…
Lesson 3

Java How To Swap Two Variables

Exchange the values of two variables using a temporary variable:

Read lesson →Loading…
Lesson 4

Java How To Find Even or Odd Numbers

Find out if a number is even or odd:

Read lesson →Loading…
Lesson 5

Java How To Reverse a Number

Take an integer and print it in reverse order:

Read lesson →Loading…
Lesson 6

Java How To Find Positive or Negative Numbers

Find out if a number is positive or negative:

Read lesson →Loading…
Lesson 7

Java How To Find the Square Root of a Number

You can use Math.sqrt() to find the square root of a number:

Read lesson →Loading…
Lesson 8

Java How To Get the Area of a Rectangle

The area of a rectangle can be found by multiplying the length of the rectangle by the width:

Read lesson →Loading…
Lesson 9

Java How To - Convert Celsius to Fahrenheit

Use the formula F = C * 9/5 + 32 to convert temperatures:

Read lesson →Loading…
Lesson 10

Java How To - Sum of Digits

Add up all digits (e.g., 352: 3 + 5 + 2 = 10):

Read lesson →Loading…
Lesson 11

Java How To Check Armstrong Number

An Armstrong number is equal to the sum of its digits raised to the power of the number of digits (e.g. 153).

Read lesson →Loading…
Lesson 12

Java How To Generate Random Numbers

Math.random() returns a random number between 0.0 (inclusive), and 1.0 (exclusive):

Read lesson →Loading…
Lesson 13

Java How To Count Words

You can easily count the number of words in a string with the following example:

Read lesson →Loading…
Lesson 14

Java How To - Count Vowels in a String

Loop through each character and count a, e, i, o, u (case-insensitive).

Read lesson →Loading…
Lesson 15

Java How To Remove Vowels from a String

Delete all vowels ( a, e, i, o, u ) from a string (case-insensitive).

Read lesson →Loading…
Lesson 16

Java How To Count Digits in a String

Go through each character and count how many are digits (0-9).

Read lesson →Loading…
Lesson 17

Java How To Reverse a String

You can easily reverse a string by characters with the following example:

Read lesson →Loading…
Lesson 18

Java How To - Palindrome Check

Explanation: We compare the first character with the last, the second with the second-last, and so on. - If all pairs match, the string is a

Read lesson →Loading…
Lesson 19

Java How To Check Anagram Strings

Two strings are anagrams if they contain the same characters in a different order:

Read lesson →Loading…
Lesson 20

Java How To Convert a String to an Array

There are many ways to convert a string to an array. The simplest way is to use the toCharArray() method:

Read lesson →Loading…
Lesson 21

Java How To - Remove Whitespace from a String

There are two common ways to remove whitespace in Java: using trim() and using replaceAll() .

Read lesson →Loading…
Lesson 22

Java How To - Character Frequency in a String

Use a HashMap to count how many times each character appears:

Read lesson →Loading…
Lesson 23

Java How To Calculate the Sum of Elements

Get the sum of array elements:

Read lesson →Loading…
Lesson 24

Java How To Find the Average of Array Elements

Create a program that calculates the average of different ages:

Read lesson →Loading…
Lesson 25

Java How To Sort an Array

You can use the sort() method, found in java.util.Arrays , to sort an array:

Read lesson →Loading…
Lesson 26

Java How To - Smallest Element in an Array

Create a program that finds the lowest age among different ages:

Read lesson →Loading…
Lesson 27

Java How To - Largest Element in an Array

Scan the array and keep track of the biggest value found so far:

Read lesson →Loading…
Lesson 28

Java How To - Second Largest Array Element

Find the second highest number without sorting the whole array:

Read lesson →Loading…
Lesson 29

Java How To Find Min and Max in Array

Go through the array and keep track of the highest and lowest values:

Read lesson →Loading…
Lesson 30

Java How To - Merge Two Arrays

Combine two int arrays into a single array:

Read lesson →Loading…
Lesson 31

Java How To - Remove Duplicates from an Array

Convert an array into a Set to remove duplicates:

Read lesson →Loading…
Lesson 32

Java How To Find Duplicates in an Array

Print which elements appear more than once:

Read lesson →Loading…
Lesson 33

Java How To - Shuffle an Array

Randomly change the order of elements in an array using Collections.shuffle() :

Read lesson →Loading…
Lesson 34

Java How To - Calculate Factorial of a Number

Use a loop to calculate the factorial of a given number:

Read lesson →Loading…
Lesson 35

Java How To - Fibonacci Sequence

Print the first 10 numbers of the Fibonacci sequence:

Read lesson →Loading…
Lesson 36

Java How To Find the GCD

The GCD (Greatest Common Divisor) is the largest number that divides two numbers without leaving a remainder.

Read lesson →Loading…
Lesson 37

Java How To - Check if a Number Is Prime

A prime number is only divisible by 1 and itself.

Read lesson →Loading…
Lesson 38

Java How To Loop Through an ArrayList

Loop through the elements of an ArrayList :

Read lesson →Loading…
Lesson 39

Java How To Loop Through a HashMap

Loop through the items of a HashMap with a for-each loop.

Read lesson →Loading…
Lesson 40

Java How To Loop Through an Enum

The enum type has a values() method, which returns an array of all enum constants. This method is useful when you want to loop through the constants of an enum:

Read lesson →Loading…