java学习记录chapter1

自学java语言已经快快2周了,总体而言,进度不快。学习的教材是几年前买的《java语言程序设计第八版基础篇》。坦白说,java在大学中已经学习过,但是毕业已经10年,虽然工作中还依旧和系统开发有那么一点点的联系,但是所有的知识点基本上已经还给老师。拿起教材的那一刻,自己完全是一脸懵逼的感觉,脑海中是那经典的三连问:“我是谁?我在哪?我要干什么?”
本身的工作是一个机关部门的工作人员,由于单位性质的原因,除了朝九晚五的工作,空余时间坦白说还是挺多的。恰好自家的孩子也要开始他漫漫的学习年月,自己一算计,正好言传不如身教,自己也开始好好学习,也正好给孩子一个正确地榜样。
原本并不想写blog,把自己的学习历程给记录下来的,但是后来一想,记录下的东西, 不仅仅是给自己一个良好的行为习惯,也可以为以后的回顾现在的日子留下一个印记。闲话不多说,下面先来点前段时间的学习。截止今天,本人按照学习教材的内容学习了6章,除去第一章的前言和基础内容外,还学习了基础的程序设计、选择语句、循环语句、方法,正在学习一维数组的内容。坦白说,学习的内容不多,但是本人把教材后面所有的编程练习题全部进行上机实测,无论题目多简单,都会将代码进行测试。恰逢疫情严重,本人也需要上卡点进行值班管理,因此大部分的时间都花在了编程题目的上机测试中。
最后,上一段程序,也是教材联系题中的一题,个人觉得挺有意义的。(一个简单的石头剪刀布的程序,连续赢两局才算赢。)

import java.util.Scanner;
public class test4_34{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
			int countofcomputer = 0;
			int countofperson = 0;
			int countofdraw = 0;		
		while (true){			
			System.out.print("Enter a number,scissor(0),rock(1),paper(2): ");
			int guess = input.nextInt();
			int computer = (int)(Math.random() * 3);
			switch(guess){
				case 0 :{
					if (computer == 0){
						System.out.println("The computer is scissor. You are scissor too. It is a draw!");
						countofdraw++;
					}
					else if (computer == 1){
						System.out.println("The computer is rock. You are scissor. Computer won!");
						countofcomputer++;
					}
					else{
						System.out.println("The computer is paper. You are scissor. You won!");
						countofperson++;
					}
					break;
				}
				case 1 :{
					if (computer == 0){
						System.out.println("The computer is scissor. You are rock. You won!");
						countofperson++;
					}
					else if (computer == 1){
						System.out.println("The computer is rock. You are rock too. It is a draw!");
						countofdraw++;
					}
					else{
						System.out.println("The computer is paper. You are rock. Computer won!");
						countofcomputer++;
					}
					break;
				}
				case 2:{
					if (computer == 0){
						System.out.println("The computer is scissor. You are paper. Computer won!");
						countofcomputer++;
					}
					else if (computer == 1){
						System.out.println("The computer is rock. You are paper. You won!");
						countofperson++;
					}
					else{
						System.out.println("The computer is paper. You are paper too. It is a draw!");
						countofdraw++;
					}
					break;
				}
				default: System.out.println("You enter the wrong number!");
						 //System.exit(0);
						 break;
			}
			
			if (countofcomputer == 2){
				System.out.println("The computer won the game!");
				break;
			}
			else if (countofperson == 2){
				System.out.println("You won the game!");
				break;
			}
			else if (countofcomputer == 1){
				countofperson = 0;
				countofdraw = 0;
				continue;
			}
			else if (countofperson == 1){
				countofcomputer = 0;
				countofdraw = 0;
				continue;
			}
			else if (countofdraw == 1){
				countofcomputer = 0;
				countofperson = 0;
				countofdraw = 0;
			}
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值