Help Please!! Write Java statements to do the following: Declare an array named
ID: 3546723 • Letter: H
Question
Help Please!!
Write Java statements to do the following: Declare an array named alpha of 5 rows and 10 columns of type char. Initialize each element of the array alpha, from step 1, to the character 'B'. Next write a code snippet using loops to store 'A' in first and last row of alpha, and the first and last column of alpha, all other cells should contain 'Z'. A A A A A A Z Z Z A A Z Z Z A A Z Z Z A A Z Z Z A A Z Z Z A A Z Z Z A A Z Z Z A A Z Z Z A A A A A A Consider the following declarations: What is stored in beta after each of the following statements executes:Explanation / Answer
public class ArrayTest{
public static void main(String[] args) {
char[][] alpha = new char[5][10];
// Initializing with 'B'
for(int i=0; i<5; i++ ) {
for(int j=0;j<10;j++) {
alpha[i][j] = 'B';
}
}
for(int i=0; i<5; i++ ) {
for(int j=0;j<10;j++) {
if (i==0 || i==4) {
alpha[i][j] = 'A';
}
else if(j==0 || j==9) {
alpha[i][j] = 'A';
}
else {
alpha[i][j] = 'Z';
}
}
}
for(int i=0; i<5; i++ ) {
for(int j=0;j<10;j++) {
System.out.print(alpha[i][j] + " ");
}
System.out.println();
}
}
}
Output:
A A A A A A A A A A
A Z Z Z Z Z Z Z Z A
A Z Z Z Z Z Z Z Z A
A Z Z Z Z Z Z Z Z A
A A A A A A A A A A
b)
Output:
0 0 0
0 4 0
0 0 8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.