Answer:
The debugged program is as follows:
A=2
B=2
For I=1 to 10
PRINT A
TEMP = A
A=B
B=TEMP+A
NEXT I
END
Explanation:
First, the value of B should be changed to 4 (because the second term of the sequence is 2
Next, change Display to Print because Q-basic uses the print keyword to display output
The sequence is not properly generated. So, I update that part of the program to:
<em>For I=1 to 10
</em>
<em>PRINT A
</em>
<em>TEMP = A
</em>
<em>A=B
</em>
<em>B=TEMP+A
</em>
<em>NEXT I
</em>
<em />
Lastly, the loop is controlled by variable I (not X).
So change NEXT X to NEXT I
Answer:
#include <iostream>
using namespace std;
void matrix(){
int row = 5, col = 6;
int myarr[row][col];
for (int i = 0; i < 5; i++){
for (int x = 0; x < 6; x++){
if (i == 0){
myarr[i][x] = (x+1)*(x+1);
}else if ( x == 0){
myarr[i][x] = (i+1)*(i+1)*(i+1);
} else if ( i == x){
myarr[i][x] = (i+1);
} else{
myarr[i][x] = myarr[i-1][x] + myarr[i][x-1];
}
}
}
for (int i = 0; i < 5; i++){
for (int x = 0; x < 6; x++){
cout<< myarr[i][x] << " ";
}
cout<< "\n";
}
}
int main(){
matrix();
}
Explanation:
The C++ source code defines a two-dimensional array that has a fixed row and column length. The array is a local variable of the function "matrix" and the void function is called in the main program to output the items of the array.
Answer:
public ArrayList onlyBlue(String[] clothes){
ArrayList<String> blueCloths = new ArrayList<>();
for(int i =0; i<clothes.length; i++){
if(clothes[i].equalsIgnoreCase("blue")){
blueCloths.add(clothes[i]);
}
}
return blueCloths;
}
Explanation:
- Create the method to accept an Array object of type String representing colors with a return type of an ArrayList
- Within the method body, create and initialize an Arraylist
- Use a for loop to iterate the Array of cloths.
- Use an if statement within the for loop to check if item equals blue and add to the Arraylist.
- Finally return the arrayList to the caller