Java Examples

HowToDoInJava AMP Logo

Java Program to Add Two Integers

Learn to write a simple Java program to add two integers and display their sum in the console. 1. Java example to add two integers In given Java exmple, we have three int type variables i.e. firstInteger, secondInteger and sum. We have assigned values to the first two integers, and then we have added them. …

Program to calculate average of N numbers

Learn to calculate the average of the given N numbers in Java using three different methods. All methods are different based on how they provide the input to the program. 1. Algorithm for calculating the average In simple words, to calculate the average of N numbers we have to add …

Count Vowels and Consonants in Java

Learn the different ways of counting the number of vowels and consonants in a given string using the Java 8 Streams and simple iteration.

Java program to reverse words in string without using functions

In these java programs, learn to reverse the words of a string in Java without using api functions. We can reverse the words of string in two ways: Reverse each word’s characters but the position of word in string remain unchanged. Reverse the string word by word but each word’s …

Java program to swap two numbers

Learn to swap two numbers in given two Java programs. First program uses a temporary variable while second program does not uses any temp variable.

Java Program to Check Deficient number

Learn to write a simple java program to verify if a given number is deficient number or not. The value 2n − σ(n) is called the number’s deficiency.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.