Category: Java Examples

python tutorials and learn python

Created with Sketch.

Java Program to Calculate Average Using Arrays

Java Program to Calculate Average Using Arrays In this program, you’ll learn to calculate the average of the given arrays in Java. Example: Program to Calculate Average Using Arrays public class Average { public static void main(String[] args) { double[] numArray = { 45.3, 67.5, -45.6, 20.34, 33.0, 45.6 }; double sum = 0.0; for…
Read more

Java Program to calculate the power using recursion

Java Program to calculate the power using recursion In this program, you’ll learn to calculate the power of a number using a recursive function in Java. Example: Program to calculate the power using recursion public class Power { public static void main(String[] args) { int base = 3, powerRaised = 4; int result = power(base,…
Read more

Java Program to Reverse a Sentence Using Recursion

Java Program to Reverse a Sentence Using Recursion In this program, you’ll learn to reverse a given sentence using a recursive loop in Java. Example: Reverse a Sentence Using Recursion public class Reverse { public static void main(String[] args) { String sentence = “Go work”; String reversed = reverse(sentence); System.out.println(“The reversed sentence is: ” +…
Read more

Java Program to Convert Binary Number to Octal and vice-versa

Java Program: Convert Binary Number to Octal and Vice-Versa In this blog post, we will delve into a Java program designed to convert a binary number to octal and vice-versa. The article will provide a comprehensive explanation of the algorithm, present the Java code for implementation, and include examples with corresponding outputs. Understanding the Algorithm…
Read more

Java Program to Convert Octal Number to Decimal and vice-versa

Java Program to Convert Octal Number to Decimal and vice-versa In this program, you’ll learn to convert octal number to a decimal number and vice-versa using functions in Java. Example 1: Program to Convert Decimal to Octal public class DecimalOctal { public static void main(String[] args) { int decimal = 78; int octal = convertDecimalToOctal(decimal);…
Read more

Java Program to Convert Binary Number to Decimal and vice-versa

Java Program to Convert Binary Number to Decimal and vice-versa In this program, you’ll learn to convert binary number to a decimal number and vice-versa using functions in Java. Example 1: Program to convert binary number to decimal public class BinaryDecimal { public static void main(String[] args) { long num = 110110111; int decimal =…
Read more

Java Program to Find Factorial of a Number Using Recursion

Java Program to Find Factorial of a Number Using Recursion In this program, you’ll learn to find and display the factorial of a number using a recursive function in The factorial of a positive number n is given by: factorial of n (n!) = 1 * 2 * 3 * 4 * … * n…
Read more

Java Program to Find the Sum of Natural Numbers using Recursion

Java Program to Find the Sum of Natural Numbers using Recursion In this program, you’ll learn to find the sum of natural number using recursion in Java. This is done with the help of a recursive function. The positive numbers 1, 2, 3… are known as natural numbers. The program below takes a positive integer…
Read more

Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers In this program, you’ll learn to check whether a given number can be expressed as a sum of two prime numbers or not. This is done with the help of loops and break statements in Java. To accomplish this…
Read more

Java Program to Make a Simple Calculator Using switch…case

Java Program to Make a Simple Calculator Using switch…case In this program, you’ll learn to make a simple calculator using switch..case in Java. This calculator would be able to add, subtract, multiply and divide two numbers. Example: Simple Calculator using switch Statement import java.util.Scanner; public class Calculator { public static void main(String[] args) { Scanner…
Read more