> of 3 Two dimensional (2D) array 1. Declare a 2D array z of 100 arrays and 5 el
ID: 3699945 • Letter: #
Question
> of 3 Two dimensional (2D) array 1. Declare a 2D array z of 100 arrays and 5 elements of type double in each array 2. Set the value of the 3rd element of the 90th array in array z to 88.876 3. Set the value of the Sth element of the 100th array to five times the 2nd element of the 44th array in array z 4. Display the value of the 4th element of the 55th array in array 5. Use the length command to compute the index of the last array in array 6. Use the length command to compute the index of the last lement in the 1st array in array 7. What is the output of this code? for (int x 1;x
Explanation / Answer
NOTE: I have completed your assignment and below are the details. Please check and let me know if you have any questions. I will revert back within 24 hours.
9) Ans:
// Declaring the 2D array student_info
String[][] student_info = {
{"1", "John", "Doe", "Main St."},
{"2", "Mary", "Joe", "Rose Ln."},
{"3", "Kim", "Lee", "Market St."}
};
Explanation:
1) Declares a 2D array student_info
2) Each individual element of the array is a one-dimensional array containing student Id, first, lastname and address.
10) Ans:
Code:
Unix Terminal> cat Student1.java
class Student1{
public static void main(String[] args){
// Declaring the 2D array student_info
String[][] student_info = {
{"1", "John", "Doe", "Main St."},
{"2", "Mary", "Joe", "Rose Ln."},
{"3", "Kim", "Lee", "Market St."}
};
// Displaying all elements in the array student_info
for (int i = 0; i < student_info.length; i++){
for(int j = 0; j < student_info[i].length; j++)
System.out.print(student_info[i][j] + " ");
System.out.println();
}
}
}
Code output snapshot:
Unix Terminal> javac Student1.java
Unix Terminal> java Student1
1 John Doe Main St.
2 Mary Joe Rose Ln.
3 Kim Lee Market St.
Unix Terminal>
11) Ans:
Code:
Unix Terminal> cat Student2.java
class Student2{
public static void main(String[] args){
// Declaring the 2D array student_info
String[][] student_info = {
{"1", "John", "Doe", "Main St."},
{"2", "Mary", "Joe", "Rose Ln."},
{"3", "Kim", "Lee", "Market St."}
};
// Display all elements in second array in array student_info
for(int j = 0; j < student_info[1].length; j++)
System.out.print(student_info[1][j] + " ");
System.out.println();
}
}
Unix Terminal>
Code output snapshot:
Unix Terminal> javac Student2.java
Unix Terminal> java Student2
2 Mary Joe Rose Ln.
Unix Terminal>
12) Ans:
Code:
Unix Terminal> cat Student3.java
class Student3{
public static void main(String[] args){
// Declaring the 2D array student_info
String[][] student_info = {
{"1", "John", "Doe", "Main St."},
{"2", "Mary", "Joe", "Rose Ln."},
{"3", "Kim", "Lee", "Market St."}
};
// Display all first and last name in array student_info
for (int i = 0; i < student_info.length; i++){
for(int j = 1; j < 3; j++)
System.out.print(student_info[i][j] + " ");
System.out.println();
}
}
}
Unix Terminal>
Code output snapshot:
Unix Terminal> javac Student3.java
Unix Terminal> java Student3
John Doe
Mary Joe
Kim Lee
Unix Terminal>
13) Ans:
Code:
Unix Terminal> cat Student4.java
import java.util.Scanner;
class Student4{
public static void main(String[] args){
// creating scanner object to read user input
Scanner sc = new Scanner(System.in);
// Declaring the 2D array student_info
String[][] student_info = {
{"1", "John", "Doe", "Main St."},
{"2", "Mary", "Joe", "Rose Ln."},
{"3", "Kim", "Lee", "Market St."}
};
System.out.println("Enter a student ID? ");
String id = sc.nextLine();
// get first name, last name and address based on user provided student Id
for (int i = 0; i < student_info.length; i++){
for(int j = 0; j < student_info[i].length; j++)
if(id.equals(student_info[i][0]))
System.out.print(student_info[i][j] + " ");
System.out.println();
}
}
}
Unix Terminal>
Code output snapshot:
jUnix Terminal> java Student4
Enter a student ID?
1
1 John Doe Main St.
Unix Terminal> java Student4
Enter a student ID?
3
3 Kim Lee Market St.
Unix Terminal>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.