Please answer all the parts of question 1 this should be done in java. 1. Call c
ID: 3695474 • Letter: P
Question
Please answer all the parts of question 1 this should be done in java.
1. Call class Arrays functions to finish the following task
(a) sort all elements in ascending order for an array (doubleArray)
(b) fill value 8 to each element for an int array (filledIntArray)
(c)Check if the two arrays (intArray intAnotheArray) are equal with returning a boolean type
(d)Check if there is an element value equals 5 within a sorted array (intArray) and return the position
(e) Make a copy of an array (intArray) to another array (intArrayCopy)
Explanation / Answer
1. sort all elements in ascending order for an array (doubleArray)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication_doublearray;
/**
*
* @author RAM
*/
import java.util.Arrays;
class DoubleArraySort {
public static void main(String[] args) {
//create double array
double[] d1 = new double[]{3,2,5,4,1};
//print original double array
System.out.print("Original Array : ");
for(int index=0; index < d1.length ; index++)
System.out.print(" " + d1[index]);
Arrays.sort(d1);
//print sorted double array
System.out.print(" Sorted double array : ");
for(int index=0; index < d1.length ; index++)
System.out.print(" " + d1[index]);
}
}
C. Check if the two arrays (intArray intAnotheArray) are equal with returning a boolean type
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author RAM
*/
public class comparision {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int [] array1;
int [] array2;
compareArrays(int[] array1, int[] array2)
{
boolean b = true;
for (int i = 0; i < array2.length; i++) {
if (array2[i] == array1[i]) {
System.out.println("true");
}
}
else {
boolean b = false;
System.out.println("False");
}
}
return b;
}
}