数组代替问题 真诚请求帮助 已经3天了 都快哭了
import java.util.*;
public class Slide{
private char[][] cells;
public Slide(){
cells= new char[4][4];
}
public Slide(char[][] cells){
for(int row=0; row<cells.length; row++)
for(int column = 0; column<cells[row].length; column++)
this.cells = cells;
}
public void print(){
{
for(char[] a: cells){
for(char c: a){
System.out.print(c+" ");
}
System.out.println();
}
}
}
public void clear(){
for(char[] a : cells) {
Arrays.fill(a, ' ');
}
}
public void project(Slide other){
/*我的问题出在这里 是要合并数值
cells的值比如是
a b c d
e f g h
i j k l
m n o p
other的值比如是
'' '' x ''
'' x '' ''
'' '' x ''
'' x '' ''
合并成为
a b x d
e x g h
i j x l
m x o p
这怎么做啊 请大家帮忙 给点建议都好 谢谢了 */
}
public void move(int row, int col){
}
}
数组代替,java?
[解决办法]
public class ArrayTest {
/**
* @param args
*/
public static void main(String[] args) {
Slide s1 = new Slide(new char[][]{{'a','b','c','d'},{'e','f','g','h'},{'i','j','k','l'},{'m','n','o','p'}});
Slide s2 = new Slide(new char[][]{{' ',' ','x',' '},{' ','x',' ',' '},{' ',' ' ,'x',' '},{' ','x',' ',' '}});
s1.project(s2);
for(char[] cells : s1.getCell()){
System.out.println(Arrays.toString(cells));
}
}
}
class Slide {
private char[][] cells;
public Slide() {
cells = new char[4][4];
}
public Slide(char[][] cells) {
for (int row = 0; row < cells.length; row++)
for (int column = 0; column < cells[row].length; column++)
this.cells = cells;
}
public void print() {
for (char[] a : cells) {
for (char c : a) {
System.out.print(c + " ");
}
System.out.println();
}
}
public void clear() {
for (char[] a : cells) {
Arrays.fill(a, ' ');
}
}
public char[][] getCell(){
return this.cells;
}
public void project(Slide other) {
char[][] otherCells = other.getCell();
char[][] temp = new char[4][5];
int index = 0;
for(int i = 0 ;i < this.cells.length ;i++){
for(int j = 0; j< cells[i].length;j++ ){
if(otherCells[i][j] == 'x'){
temp[i][j] = 'x';
index++;
}else{
temp[i][j] = cells[i][j];
}
}
index++;
}
this.cells = temp;
temp = null;
}
public void move(int row, int col) {
}
}