1.第一次调试,并且分析出问题
在这次学习中,首先研究了java Eclipse的调试;其次自己一步步锁定了bug所在;发现了switch语句break的重要性。
附上源码:
package test;public class Cell {int row;int col;int rowStar;int colStar;Cell(int row,int col){this.row=row;this.col=col;}public void setStarLocation(int row,int col){this.rowStar=row;this.colStar=col;}public static void printCell(Cell cell) {int totalRow = cell.row;int totalCol = cell.col;//打印场地for (int row = 0; row < totalRow; row++) {for (int col = 0; col < totalCol; col++) {if (cell.rowStar == row && cell.colStar == col) {//打印指定的格子System.out.print("* ");} else {System.out.print("- ");}}System.out.println();}}}
package test;import java.util.Scanner;import java.lang.System;
public class CellGame{ public static void main(String[] args) { Cell cell=new Cell(16,9); cell.setStarLocation(5, 5); System.out.println("decide the move"); int y=keyboardTest(cell); System.out.println("y is"+y); cell.printCell(cell); } //键盘输入检测 public static int keyboardTest(Cell cell) { Scanner sca=new Scanner(System.in); //System.out.println("decide the move"); int way=sca.nextInt(); switch(way) { case 1:cell.rowStar=cell.rowStar+1; break; case 2:cell.rowStar-=cell.rowStar; break; case 3:cell.colStar-=cell.colStar; break; case 4:cell.colStar+=cell.colStar; break; } sca.close(); return way; } /*public static void printCell(Cell cell) { int totalRow = 20; int totalCol = 10; //打印场地 for (int row = 0; row < totalRow; row++) { for (int col = 0; col < totalCol; col++) { if (cell.row == row && cell.col == col) { //打印指定的格子 System.out.print("* "); } else { System.out.print("- "); } } System.out.println(); } } */}
最后
以上就是拉长冬日最近收集整理的关于day07 第一次调试,并且分析出问题的全部内容,更多相关day07内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复