NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public static int summationOfMaximumAndMinimumOfanArray(int[] myarray){
//return summation of minimum and maximum elements of the method parameter myarray
int sum=0;
int max=myarray[0];
int min=myarray[0];
for(int i=0; i<myarray.length;i++){
if(myarray[i]>max)
max=myarray[i];
}
for( int j=0; j<myarray.length;j++){
if(myarray[j]<min)
min=myarray[j];
}
sum=min+max;
return sum;
}

public static int numberOfDifferentElement(int[] myarray){
//return the number of different element in the method parameter myarray
// if myarray={2,3,2,4,2,3,2} then the number of different element is 3

Arrays.sort(myarray);
if (myarray.length == 0) {
return 0;
}
int count=1;
for(int i=0; i<myarray.length-1;i++){
if(myarray[i]!=myarray[i+1]){
count++;
}
}
return count;
}

public static int[] reverseOfAnArray(int[] myarray){

//find the reverse of the method parameter myarray and return resulting array
// if myarray={2,3,5,4} then return resulting array as {4,5,3,2}

int [] result=new int[myarray.length];
for (int i=0, j=result.length-1; i<myarray.length;i++, j--){
result[j]=myarray[i];
}
return result;
}

public static int indexOfTheSmallestElement(int[] myarray){
//return index of the smallest element in the method parameter myarray
// Let myarray be {3,5,7,2,4}. Since the smallest element is 2 return the index of 2, it is 3

int min = myarray[0];
int indexOfMin=0;
for(int i=0;i<myarray.length;i++){
if(myarray[i]<min){
min=myarray[i];
indexOfMin =i;
}
}
return indexOfMin;
}

public static boolean isequal(int[] array1, int[] array2){
//return true if the method parameters array1 and array2 are strictly equal or return false otherwise
// if array1={1,2,3,4} and array2={1,2,3,4] then array1 and array2 are equal
// if array1={1,2,3,4} and array2={1,2,4,3] then array1 and array2 are NOT equal
boolean equal=Arrays.equals(array1, array2);
if(equal!=true){
return false;
}
return equal;
}



public static int theMostRepeatedElement(int[] myarray){
//return the most repeated element in the method parameter myarray
// if myarray={1,2,2,3,2,4} then the most repeated element is 2

Arrays.sort(myarray);
int counting = 1, tempCount;
int repeated = myarray[0];
int temp = 0;
for (int i = 0; i < myarray.length - 1; i++){
temp = myarray[i];
tempCount = 0;
for (int j = 1; j < myarray.length; j++){
if (temp == myarray[j])
tempCount++;
}
if (tempCount > counting){
repeated = temp;
counting = tempCount;
}
}
return repeated;
}

public static int[] insertAnElementIntoAnIndex(int[] myarray,int i,int k){
//insert the k into the index i of the method parameter myarray and return resulting array
// if myarray={2,3,5,1,4}, i=2 and k=10 then the resulting array would be {2,3,10,5,1,4}

int [] newarray=new int [myarray.length+1];
for(int j=0 ;j<newarray.length;j++){
if(j<i){
newarray[j]=myarray[j];
}
else if(j==i){
newarray[i]=k;
}
else{
newarray[j]=myarray[j-1];}
}
return newarray;
}

public static int[] removeAnElementFromAnIndex(int[] myarray,int i){
//remove an element from the index i of the method parameter myarray
// if myarray={2,3,5,1,4} and i=2 then the resulting array would be {2,3,1,4}

int[] result = new int[myarray.length-1];

System.arraycopy(myarray, 0, result, 0, i);
System.arraycopy(myarray, i+1, result, i, result.length-i);

return result;
}

public static int [][] multiplyAMatrixByAnInteger(int [][] myarray, int i){
//suppose the method parameter myarray is a 2 Dimensional MxN matrix
//Multiply all of the elements of the myarray by the integer i and return the resulting MxN array
// further information about multiplication of a matrix by an integer visit http://www.purplemath.com/modules/mtrxmult.htm

int array[][] = new int[myarray.length][myarray[0].length];
for( int k = 0; k < myarray.length; k++){
for(int j=0; j<myarray[0].length; j++){

array[k][j] = myarray[k][j] * i;
}

}
return array;
}

public static double determinatOfaMatrix(double [][] myarray){
//suppose the method parameter myarray is a 2 Dimensional 3x3 matrix
//Calculate the determinat of the myarray and return the resulting value
// further information about determinant of a matrix visit http://www.purplemath.com/modules/determs2.htm
double [][] newarray = Arrays.copyOf(myarray, myarray.length);
double plus=(newarray[0][0]*newarray[1][1]*newarray[2][2]+newarray[0][1]*newarray[1][2]*newarray[2][0]+newarray[0][2]*newarray[1][0]*newarray[2][1]);
double minus=(newarray[0][2]*newarray[1][1]*newarray[2][0]+newarray[0][0]*newarray[1][2]*newarray[2][1]+newarray[0][1]*newarray[1][0]*newarray[2][2]);
double determinant=plus - minus;

return determinant;
}

public static double [][] transposeOfaMatrix(double [][] myarray){
//suppose the method parameter myarray is a 2 Dimensional MxN matrix
//find the transpose of the myarray and return the resulting 2 Dimensional MXN array
// further information about transpose of a matrix visit http://www.mathwords.com/t/transpose_of_a_matrix.htm

if (myarray == null || myarray.length == 0)
return myarray;

double [] [] result=new double[myarray[0].length][myarray.length];

for (int i = 0; i < myarray.length; i++) {
for (int j = 0; j < myarray[0].length; j++) {
result[j][i]= myarray[i][j] ;
}
}
return result;
}

public static double [][] summationOfTwoMatrix(double[][] myarray1, double[][] myarray2){
//suppose myarray1 and myarray2 are a 2 Dimensional MxN matrix
//find the summation of the myarray1 and myarray2 and return the resulting 2 Dimensional MXN array
// further information about matrix summation visit http://www.mathportal.org/linear-algebra/matrices/matrix-operations.php

double [] [] sumarray= new double[myarray1.length][myarray1[0].length];
for(int i=0; i<myarray1.length; i++){
for(int j=0; j<myarray2[0].length; j++){
sumarray [i] [j]= myarray1 [i][j] + myarray2 [i][j];
}
}

return sumarray;
}



public static double [][] multiplicationOfTwoMatrix(double [][] myarray1, double [][] myarray2){
//suppose myarray1 and myarray2 are 2 Dimensional NxN matrix
//find the multiplication of the matrices myarray1 and myarray2 and return the resulting NXN array
// further information about matrix multiplication visit http://www.mathportal.org/linear-algebra/matrices/matrix-operations.php

double [] [] result= new double[myarray1.length][myarray2[0].length];
for (int i=0; i<myarray1.length;i++){
for(int j=0; j<myarray2[0].length; j++){
for(int m=0; m<myarray1[0].length;m++){
result [i][j] +=myarray1[i][m] * myarray2[m][j];
}
}
}

return result;
}


public static int numberOfElementsInIntersectionOfTwoArray(int [] array1,int [] array2){
//find the number of elements in the intersection of the method parameters array1 and array2
//if array1={1,3,2,5,9,6} and array2={4,6,8,1,3,2} then the intersection is {1,3,2,6}
//since there are 4 elements in the intersection, return 4.
//if there is no element in the intersection return 0.

Arrays.sort(array1);
Arrays.sort(array2);

int samevalues=0;

for(int i=0; i<array1.length;i++){
for(int j=0; j<array2.length; j++){
if(array1[i]==array2[j]){
samevalues++;
if(array1[i]!=array2[j])
return 0;
}
}
}

return samevalues;
}

public static int numberOfElementsInUnionOfTwoArray(int [] array1,int [] array2){
//find the number of elements in the union of the method parameter array1 and array2
//if array1={1,3,2,5,9,6} and array2={4,6,8,1,3,2} then the union is {1,2,3,4,5,6,8,9}
//since there are 8 elements in the union, return 8.
//if there is no element in the union return 0.
Arrays.sort(array1);
Arrays.sort(array2);
int count1=0;
int count2=0;
int newarray [] = new int [array1.length+array2.length];
for(int i=0; i<array1.length;i++){
if(newarray[i]==array1[i]){
count1++;
}
}
for(int j=0; j<array1.length;j++){
if(newarray[j]==array1[j]){
count2++;
}
}
return count1+count2;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.