Twin Islands There are two islands, one made of \'!\' in the top left and one ma
ID: 3825652 • Letter: T
Question
Twin Islands
There are two islands, one made of '!' in the top left and one made of '?' in the bottom right. There is a border in the middle and ocean everywhere else.
Running total
You print an NxN matrix of numbers seperated by commas.
The pattern is simply a running total of values where each row contains only N values.
Make use of the function std::to_string for converting numeric values to strings
please use for loop
someone help me do that. in addition, the number of rows and vertical is given by user. Thank you very much
Explanation / Answer
1. For Twin IsLand need more information
2. N*N Matrix
public class Matrix {
public static void main(String[] args) {
Matrix matrix = new Matrix();
matrix.getMatrix(5);
}
public void getMatrix(int n) {
int number = 1;
int[][] mat = new int[n][n];
for(int i=0; i<n; i++) {
for (int j=0; j<n; j++){
mat[i][j] = number;
number++;
}
}
for(int i=0; i<n; i++) {
for (int j=0; j<n; j++){
if(i == n-1 && j == n-1) {
System.out.print(String.valueOf(mat[i][j]).toString());
} else {
System.out.print(String.valueOf(mat[i][j]).toString() + ",");
}
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.