Category: Java Examples

python tutorials and learn python

Created with Sketch.

Java Program to Add Two Complex Numbers by Passing Class to a Function

Java Program to Add Two Complex Numbers by Passing Class to a Function In this program, you’ll learn to add two complex numbers in Java by creating a class named Complex and passing it into a function add(). Example: Add Two Complex Numbers public class Complex { double real; double imag; public Complex(double real, double…
Read more

Java Program to Sort Elements in Lexicographical Order (Dictionary Order)

Java Program to Sort Elements in Lexicographical Order (Dictionary Order) In this program, you’ll learn to sort the element words in lexicographical order using a for loop and if else in Java. Example: Program to Sort Strings in Dictionary Order public class Sort { public static void main(String[] args) { String[] words = { “Ruby”,…
Read more

Java Program to Count the Number of Vowels and Consonants in a Sentence

Java Program to Count the Number of Vowels and Consonants in a Sentence In this program, you’ll learn to count the number of vowels, consonants, digits and spaces in a given sentence using if else in Java. Example: Program to count vowels, consonants, digits and spaces public class Count { public static void main(String[] args)…
Read more

Java Program to Find the Frequency of Character in a String

Java Program to Find the Frequency of Character in a String In this program, you’ll learn to find the occurence (frequency) of a character in a given string.   Example: Find the Frequency of Character public class Frequency { public static void main(String[] args) { String str = “This website is awesome.”; char ch =…
Read more

Java Program to Find Transpose of a Matrix

Java Program to Find Transpose of a Matrix In this program, you’ll learn to find and print the transpose of a given matrix in Java.   Transpose of a matrix is the process of swapping the rows to columns. For 2×3 matrix, Matrix a11 a12 a13 a21 a22 a23 Transposed Matrix a11 a21 a12 a22…
Read more

Java Program to Multiply two Matrices by Passing Matrix to a Function

Java Program to Multiply two Matrices by Passing Matrix to a Function In this program, you’ll learn to multiply two matrices using a function in Java.   For matrix multiplication to take place, the number of columns of first matrix must be equal to the number of rows of second matrix. In our example, i.e.…
Read more

Java Program to Multiply to Matrix Using Multi-dimensional Arrays

Java Program to Multiply to Matrix Using Multi-dimensional Arrays In this program, you’ll learn to multiply two matrices using multi-dimensional arrays in Java.   For matrix multiplication to take place, the number of columns of first matrix must be equal to the number of rows of second matrix. In our example, i.e. c1 = r2…
Read more

Java Program to Add Two Matrix Using Multi-dimensional Arrays

Java Program to Add Two Matrix Using Multi-dimensional Arrays In this program, you’ll learn to add two matrices using multi-dimensional arrays in Java.   Example: Program to Add Two Matrices public class AddMatrices { public static void main(String[] args) { int rows = 2, columns = 3; int[][] firstMatrix = { {2, 3, 4}, {5,…
Read more

Java Program to Calculate Standard Deviation

Java Program to Calculate Standard Deviation In this program, you’ll learn to calculate the standard deviation using a function in Java.   This program calculates the standard deviation of a individual series using arrays. To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this…
Read more

Java Program to Find Largest Element of an Array

Java Program to Find Largest Element of an Array In this program, you’ll learn to find the largest element in an array using a for loop in Java.   Example: Find largest element in an array public class Largest { public static void main(String[] args) { double[] numArray = { 23.4, -34.5, 50.0, 33.5, 55.5,…
Read more