day07 第一次调试,并且分析出问题

1.第一次调试,并且分析出问题
在这次学习中,首先研究了java Eclipse的调试;其次自己一步步锁定了bug所在;发现了switch语句break的重要性。
附上源码:
   
   
  1. package test;
  2. public class Cell {
  3. int row;
  4. int col;
  5. int rowStar;
  6. int colStar;
  7. Cell(int row,int col)
  8. {
  9. this.row=row;
  10. this.col=col;
  11. }
  12. public void setStarLocation(int row,int col)
  13. {
  14. this.rowStar=row;
  15. this.colStar=col;
  16. }
  17. public static void printCell(Cell cell) {
  18. int totalRow = cell.row;
  19. int totalCol = cell.col;
  20. //打印场地
  21. for (int row = 0; row < totalRow; row++) {
  22. for (int col = 0; col < totalCol; col++) {
  23. if (cell.rowStar == row && cell.colStar == col) {
  24. //打印指定的格子
  25. System.out.print("* ");
  26. } else {
  27. System.out.print("- ");
  28. }
  29. }
  30. System.out.println();
  31. }
  32. }
  33. }
    
    
  1. package test;
  2. import java.util.Scanner;
  3. import java.lang.System;
  4. public class CellGame{
  5. public static void main(String[] args) {
  6. Cell cell=new Cell(16,9);
  7. cell.setStarLocation(5, 5);
  8. System.out.println("decide the move");
  9. int y=keyboardTest(cell);
  10. System.out.println("y is"+y);
  11. cell.printCell(cell);
  12. }
  13. //键盘输入检测
  14. public static int keyboardTest(Cell cell)
  15. {
  16. Scanner sca=new Scanner(System.in);
  17. //System.out.println("decide the move");
  18. int way=sca.nextInt();
  19. switch(way)
  20. {
  21. case 1:cell.rowStar=cell.rowStar+1;
  22. break;
  23. case 2:cell.rowStar-=cell.rowStar;
  24. break;
  25. case 3:cell.colStar-=cell.colStar;
  26. break;
  27. case 4:cell.colStar+=cell.colStar;
  28. break;
  29. }
  30. sca.close();
  31. return way;
  32. }
  33. /*public static void printCell(Cell cell) {
  34. int totalRow = 20;
  35. int totalCol = 10;
  36. //打印场地
  37. for (int row = 0; row < totalRow; row++) {
  38. for (int col = 0; col < totalCol; col++) {
  39. if (cell.row == row && cell.col == col) {
  40. //打印指定的格子
  41. System.out.print("* ");
  42. } else {
  43. System.out.print("- ");
  44. }
  45. }
  46. System.out.println();
  47. }
  48. } */
  49. }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值