## Matrix in Java

Posted By: Java Examples - 10:07 PM

## Creating a matrix

In this example  you will learn about array and matrix. An array is the collection of same data type values. If we create a variable of integer type then, the array of int can only store the int values. It can't store other than int data type.
Matrix: A matrix is a collection of data in rows and columns format.
In this program we are going to implement a matrix. To make a program over the two dimensional array,irst of all we have to declare class named as

## Java program to search an element in an array

Posted By: Java Examples - 8:40 AM

## Search an element in an array

Find an element from an array using Linear Searching. Linear searching is a good way to find an element from the array. The array can be of any order, it checks whether a certain element (number , string , etc. ) is in a specified array or not. Basically it is used for small arrays. In the given code, we have allowed the user to enter the numbers to be stored into the arrays. If the element is found we can return the index where the element is located in the array. If the element is not found we can return -1.

## Mean - average of array in java

Posted By: Java Examples - 7:48 PM
For this, first of all we have to define a class name "ArrayAverage" that has int type array to contain some values .Now we take a double type data that calculates the average of array ( avg = sum / array.length). And finally it will display the result on the command prompt with message by using the System.out.println().

## Maximum element in an array in java

Posted By: Java Examples - 7:28 PM
To find the maximum value in an array :

1. Assign the first (or any) array element to the variable that will hold the maximum value
2. Loop through the remaining array elements, starting at the second element (subscript 1). When a larger value is found, that becomes the new maximum.
To make this work with object types (eg String), you will have to change the type declarations of course, but you will also have to change the comparison to use .compareTo(), which must be defined for that object type. The minimum can be found by the same algorithm, simply inverting the test. It's also easy to add a test for the minimum to this loop so that both the maximum and minimum are determined within the same loop. There is one common variation on this -- sometimes it isn't the maximum value that is desired, but the index of the maximum value (eg, so it can be changed).

Java version of the Maximum element problem is given below :
```/**
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package array;

/**
*
* @author ACHCHUTHAN
*/
public class MaxElement {

public static void main(String args[]) {
int[] array = {45, 66, 77, 54, 76, 89, 86, 45, 67, 87};
//assign the first element as maximum
int maximum = array[0];
int index = -1;
//Find maximum (largest) value in array using loop
for (int i = 1; i < array.length; i++) {
if (array[i] > maximum) {
maximum = array[i];
// new maximum
index = i;
}
}
System.out.println("Maximun element : " + maximum +
"\nIndex of Maximum : " + index);
}
}

```
Output of this program is given bellow :

run:
Maximun element is : 89
Index of Maximum is : 5
BUILD SUCCESSFUL (total time: 1 second)

## Declaring an array in java

Posted By: Java Examples - 7:08 PM
An array variable is like other variables -- you must declare it, which means you must declare the type of elements that are in an array. All elements must be the same type. Write the element type name, then "[]", then the name of the array variable. The declaration allocates only enough space for a reference to an array (typically 4 bytes), but doesn't create the actual array object.

## Subtraction of two matrix in java

Posted By: Java Examples - 7:26 PM
we are going to calculate the subtraction of two matrix and containing its rows and columns. See below for better understanding to this:
In this program we are going to calculate the  subtraction  of two matrix. To make this program, we need to declare two dimensional array of type integer. Now we need to make a matrix out of it. To make the matrix we will use the for loop.

## Addition of two matrix in java

Posted By: Java Examples - 7:20 PM
we are going to calculate the sum of two matrix and containing its rows and columns. See below for better understanding to this:
In this program we are going to calculate the sum of two matrix. To make this program, we need to declare two dimensional array of type integer.