Java Articles

Page 6 of 450

Java program to print the transpose of a matrix

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

The transpose of a matrix is the one whose rows are columns of the original matrix, i.e. if A and B are two matrices such that the rows of the matrix B are the columns of the matrix A then Matrix B is said to be the transpose of Matrix A.To print the transpose of the given matrix −Create an empty matrix.Copy the contents of the original matrix to the new matrix such that elements in the [j][i] position of the original matrix should be copied to the [i][j] position of the new matrix.Print the new matrix.Examplepublic class TransposeSample{   ...

Read More

Java program to print the transpose of a matrix

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 2K+ Views

The transpose of a matrix is the one whose rows are columns of the original matrix, i.e. if A and B are two matrices such that the rows of the matrix B are the columns of the matrix A then Matrix B is said to be the transpose of Matrix A.To print the transpose of the given matrix −Create an empty matrix.Copy the contents of the original matrix to the new matrix such that elements in the [j][i] position of the original matrix should be copied to the [i][j] position of the new matrix.Print the new matrix.Examplepublic class TransposeSample{   ...

Read More

Java program to calculate mode in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 16K+ Views

In statistics math, a mode is a value that occurs the highest numbers of time. For Example, assume a set of values 3, 5, 2, 7, 3. The mode of this value set is 3 as it appears more than any other number.Algorithm1.Take an integer set A of n values. 2.Count the occurrence of each integer value in A. 3.Display the value with the highest occurrence.Examplepublic class Mode {    static int mode(int a[], int n) {       int maxValue = 0, maxCount = 0, i, j;       for (i = 0; i < n; ...

Read More

Java program to calculate mode in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 16K+ Views

In statistics math, a mode is a value that occurs the highest numbers of time. For Example, assume a set of values 3, 5, 2, 7, 3. The mode of this value set is 3 as it appears more than any other number.Algorithm1.Take an integer set A of n values. 2.Count the occurrence of each integer value in A. 3.Display the value with the highest occurrence.Examplepublic class Mode {    static int mode(int a[], int n) {       int maxValue = 0, maxCount = 0, i, j;       for (i = 0; i < n; ...

Read More

Java program to calculate the average of numbers in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 18K+ Views

An average of a set of numbers is their sum divided by their quantity. It can be defined as −average = sum of all values / number of valuesHere we shall learn how to programmatically calculate average.Algorithm1. Collect integer values in an array A of size N. 2. Add all values of A. 3. Divide the output of Step 2 with N. 4. Display the output of Step 3 as average.Examplepublic class AverageOfNNumbers {    public static void main(String args[]){       int i,total;       int a[] = {0,6,9,2,7};       int n = 5;       total = 0;       for(i=0; i

Read More

Java program to calculate the average of numbers in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 18K+ Views

An average of a set of numbers is their sum divided by their quantity. It can be defined as −average = sum of all values / number of valuesHere we shall learn how to programmatically calculate average.Algorithm1. Collect integer values in an array A of size N. 2. Add all values of A. 3. Divide the output of Step 2 with N. 4. Display the output of Step 3 as average.Examplepublic class AverageOfNNumbers {    public static void main(String args[]){       int i,total;       int a[] = {0,6,9,2,7};       int n = 5;       total = 0;       for(i=0; i

Read More

Java Program to Check if a String is Numeric

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 381 Views

ExampleYou can check if a given string is Numeric as shown in the following program.import java.util.Scanner; public class StringNumeric {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a string ::");       String str = sc.next();       boolean number = str.matches("-?\d+(\.\d+)?");       if(number) {          System.out.println("Given string is a number");       } else {          System.out.println("Given string is not a number");       }    } }OutputEnter a string :: 4245 Given string is a number

Read More

Java Program to Check if a String is Numeric

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 381 Views

ExampleYou can check if a given string is Numeric as shown in the following program.import java.util.Scanner; public class StringNumeric {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a string ::");       String str = sc.next();       boolean number = str.matches("-?\d+(\.\d+)?");       if(number) {          System.out.println("Given string is a number");       } else {          System.out.println("Given string is not a number");       }    } }OutputEnter a string :: 4245 Given string is a number

Read More

Java Program to Convert a Stack Trace to a String

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 341 Views

The Java.io.StringWriter class is a character stream that collects its output in a string buffer, which can then be used to construct a string. Closing a StringWriter has no effect.The Java.io.PrintWriter class prints formatted representations of objects to a text-output stream.Using these two classes you can convert a Stack Trace to a String.Exampleimport java.io.PrintWriter; import java.io.StringWriter; public class StackTraceToString {    public static void main(String args[]) {       try {          int a[] = new int[2];          System.out.println("Access element three :" + a[3]);       } catch (ArrayIndexOutOfBoundsException e) { ...

Read More

Java Program to Convert a Stack Trace to a String

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 341 Views

The Java.io.StringWriter class is a character stream that collects its output in a string buffer, which can then be used to construct a string. Closing a StringWriter has no effect.The Java.io.PrintWriter class prints formatted representations of objects to a text-output stream.Using these two classes you can convert a Stack Trace to a String.Exampleimport java.io.PrintWriter; import java.io.StringWriter; public class StackTraceToString {    public static void main(String args[]) {       try {          int a[] = new int[2];          System.out.println("Access element three :" + a[3]);       } catch (ArrayIndexOutOfBoundsException e) { ...

Read More
Showing 51–60 of 4,495 articles
« Prev 1 4 5 6 7 8 450 Next »
Advertisements