Lesson_3 上课笔记

本文介绍Java编程基础,包括Eclipse快捷键、代码格式化等,通过具体实例如体育课跑步计数和人机扑克游戏,演示了基本的循环和条件语句使用。深入解析游戏算法,适合Java初学者参考。
 1 import java.util.Iterator;
 2 import java.util.Scanner;
 3 
 4 public class Day3 {
 5 
 6     // eclipse的一些快捷键:
 7     // alt + / 自动提示键
 8     // ctrl + / 注释当前或选择行
 9     // ctrl + d 删除当前行或选择行
10     // alt + 上下方向键 上下移动行
11     // ctrl + shift + f 格式化代码
12     // ctrl + o 查看当前类的结构
13 
14     public static void main(String[] args) {
15         Scanner sc = new Scanner(System.in);
16         int sum = 0;
17         // 体育课跑步。
18         // for(int i = 1 ; i<=100000; i++){
19         // if(i%5==1 && i%6==5 && i%7==4 && i%11==10){
20         // System.out.println(i);
21         // }
22         // }
23         
24         for (int i = 1; i < 25; i++) {// 表示人
25             for (int j = 1; j <= i; j++) {
26                 System.out.println("跑" + j + "圈");
27             }
28         }
29         for(int i=1;i<128;i++){//ASCII
30             System.out.print(i+":" + (char)i + "  ");
31         }
32         // 执行game这个方法
33         //game();
34         System.out.println("\n请输入:");
35         String input = sc.next();
36         if(!(input.equals("y"))){//字符串要比较内容需要用equals
37             System.out.println("not yes ");
38         }else{
39             System.out.println("yes");
40         }
41     }
42 
43     public static void game() {
44         Scanner sc = new Scanner(System.in);
45         System.out.println("******人机大战******");
46         System.out.println("游戏开始……");
47         int pokerNumber = 21;
48         while (pokerNumber != 1) {
49             System.out.print("人先选(1-4):");
50             int people = sc.nextInt();
51             pokerNumber -= people;
52             System.out.println("人拿了:" + people + " 剩余:" + pokerNumber);
53             int machine = 5 - people;
54             pokerNumber -= machine;
55             System.out.println("机器开始拿牌:" + machine + " 剩余:" + pokerNumber);
56         }
57         System.out.println("还剩1根,你输了!");
58     }
59 
60 }

好好理解游戏的算法

转载于:https://www.cnblogs.com/CocoonFan/archive/2013/01/15/2861713.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值