帮忙编写一个java程序,建立一个矩阵,并能返回其中一个元素周围的值..public class MatrixNeighbors {
private int rows;
private int columns;
private int[][] matrix = new int[rows][columns];
public int[][] getMatrix() {
return matrix;
}
public void setMatrix(int[][] matrix) {
this.matrix = matrix;
}
public MatrixNeighbors(int rows, int columns) {
super();
this.rows = rows;
this.columns = columns;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public int getColumns() {
return columns;
}
public void setColumns(int columns) {
this.columns = columns;
}
public String neighbours(int row, int column) {
String result = "prints: ";
if (row = rows - 1column = columns - 1row = 0column = 0) {
for (int i = row - 1; i = row + 1; i++) {
for (int j = column - 1; j = column + 1; j++) {
if (i = 0j = 0i = rows - 1j = columns - 1) {
if (i == rowj == column) {
} else {
result += i + "," + j + ";";
}
}
}
}
} else {
return "Error!";
}
return result;
}
}
public class Test {
public static void main(String[] args) {
MatrixNeighbors m1 = new MatrixNeighbors(2, 3);
System.out.println(m1.neighbours(1, 1));
MatrixNeighbors m2 = new MatrixNeighbors(5, 4);
System.out.println(m2.neighbours(4, 3));
System.out.println(m2.neighbours(4, 4));
}
}
你好 请问你能帮我做个走迷宫的java版数据结构代码吗?用栈和队列制作 谢谢,到时候一定加分给你的2011年4月12日在人民大会堂河南厅颁发的“卫浴十大品牌”排行榜分别是:
申鹭达卫浴、
科勒卫浴
TOTO
箭牌卫浴、
和成卫浴、
美标卫浴
四维卫浴、
东鹏卫浴、
科勒卫浴、
全友卫浴 。
关于Java走迷宫的问题 。我已经有相关代码了,但是我看不懂 。麻烦高手帮忙注释一下,然后再修改点儿 。package 走迷宫;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
// 迷宫
public class Maze extends JFrame implements ActionListener {
private JPanel panel;
private JPanel northPanel;
private JPanel centerPanel;
private MazeGrid grid[][];
private JButton restart;
private JButton dostart;
private int rows;// rows 和cols目前暂定只能是奇数
private int cols;
private ListString willVisit;
private ListString visited;
private LinkedListString comed;
private long startTime;
private long endTime;
public Maze() {
rows = 25;
cols = 25;
willVisit = new ArrayListString();
visited = new ArrayListString();
comed = new LinkedListString();
init();
this.setTitle("回溯法--走迷宫");
this.add(panel);
this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void init() {
panel = new JPanel();
northPanel = new JPanel();
centerPanel = new JPanel();
panel.setLayout(new BorderLayout());
restart = new JButton("重新生成迷宫");
dostart = new JButton("开始走迷宫");
grid = new MazeGrid[rows][cols];
centerPanel.setLayout(new GridLayout(rows, cols, 1, 1));
centerPanel.setBackground(new Color(0, 0, 0));
推荐阅读
- redis本地存储图片,redis存图片 java
- css内部阴影效果,css中阴影怎么写
- win7装xp虚拟机还是win7虚拟机,win7系统装win7虚拟机教程
- 计算机毕业设计跑步app,计算机毕设一般做什么
- 包含pythonfix函数的词条
- 直播专属房源什么意思,直播专属是什么意思
- 2021国外的免费服务器,外网免费服务器
- 如何做好营销系统分析策略,如何做好营销系统分析策略的研究
- java跨域访问代码 java跨域问题解决办法