Using the IST Linux system create the following Java command line array applicat
ID: 3871372 • Letter: U
Question
Using the IST Linux system create the following Java command line array application in your home area Lab5.java.
------- Step 1: Array of Integers, Reverse Sort, Print elements values using for loop -------
Declare an array of integers named intArray and allocate memory for 5 integer types
Initialize the array elements with integer values (100, 1000, 23, 555, 356) using the Integer type not int.
Reverse sort the array intArray elements and print each array element out using iteration (loop)
You will need to import the Collections class and Arrays class to perform the reverse sort.
------- Step 2: Array of chars, Sort, Print elements values using a for loop -------
Declare an array of chars named charArray and allocate memory for 5 char types
Initialize the array elements with char values (characters G, E, Q, A, Z)
Sort the array charArray elements and print each element out using iteration (loop)
------ Step 3: Array of floats, Sort, Print elements values using a for loop -------
Declare an array of floats named floatArray and allocate memory for 5 floats
Initialize the array elements with float values (10.0, 32.5, 22.2, 99.1, 90.5)
Sort the array floatArray elements and print each element out using iteration (loop)
------ Step 4: Multidimensional array, Print elements values using a for loop -------
Declare a multidimensional array of integers named multiArray and allocate memory for 3 X 5 integers
Initialize the array elements with int values (row 1 = 1-5, row 2 = 11-15, row 3 = 21-25)
Print each row element out using a nested loop
PreviousNext
3 1000 356 100 23 10.0 22.2 32.5 90.5 99.1 12 13 14 15 21 2.3 24 25Explanation / Answer
Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.
_____________
1)
Lab5.java
import java.util.Arrays;
import java.util.Collections;
public class Lab5 {
public static void main(String[] args) {
//Creating an Integer array
Integer arr[] = new Integer[5];
//Initializing array with Integers
arr[0] = new Integer(100);
arr[1] = new Integer(1000);
arr[2] = new Integer(23);
arr[3] = new Integer(555);
arr[4] = new Integer(356);
// Sorting Integer Array in descending order
Arrays.sort(arr, Collections.reverseOrder());
//Displaying the Integer array After reverse sort
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
_________________
Output:
1000
555
356
100
23
__________________
2)
Lab5.java
import java.util.Arrays;
import java.util.Collections;
public class Lab5 {
public static void main(String[] args) {
char charArray[] = new char[5];
charArray[0] = 'G';
charArray[1] = 'E';
charArray[2] = 'Q';
charArray[3] = 'A';
charArray[4] = 'Z';
// Sorting char Array in descending order
Arrays.sort(charArray);
//Displaying the char array After reverse sort
for (int i = 0; i < charArray.length; i++) {
System.out.println(charArray[i]);
}
}
}
__________________
Output:
A
E
G
Q
Z
_________________
3)
Lab5.java
import java.util.Arrays;
import java.util.Collections;
public class Lab5 {
public static void main(String[] args) {
float floatArray[] = new float[5];
floatArray[0] = 10.0 f;
floatArray[1] = 32.5 f;
floatArray[2] = 22.2 f;
floatArray[3] = 99.1 f;
floatArray[4] = 90.5 f;
// Sorting float Array in ascending order
Arrays.sort(floatArray);
//Displaying the Integer array After sort
for (int i = 0; i < floatArray.length; i++) {
System.out.println(floatArray[i]);
}
}
}
___________________
Output:
10.0
22.2
32.5
90.5
99.1
__________________
5)
Lab5.java
Lab5.java
import java.util.Arrays;
import java.util.Collections;
public class Lab5 {
public static void main(String[] args) {
Integer multiArray[][] = new Integer[3][5];
multiArray[0][0] = new Integer(1);
multiArray[0][1] = new Integer(2);
multiArray[0][2] = new Integer(3);
multiArray[0][3] = new Integer(4);
multiArray[0][4] = new Integer(5);
multiArray[1][0] = new Integer(11);
multiArray[1][1] = new Integer(12);
multiArray[1][2] = new Integer(13);
multiArray[1][3] = new Integer(14);
multiArray[1][4] = new Integer(15);
multiArray[2][0] = new Integer(21);
multiArray[2][1] = new Integer(12);
multiArray[2][2] = new Integer(13);
multiArray[2][3] = new Integer(14);
multiArray[2][4] = new Integer(15);
for (int i = 0; i < multiArray.length; i++) {
for (int j = 0; j < multiArray[0].length; j++) {
System.out.println(multiArray[i][j]);
}
}
}
}
________________________
Output:
1
2
3
4
5
11
12
13
14
15
21
22
23
24
25
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.