Java 20210310课堂练习

练习要求:
1、
计算机随机产生两个60–100的整数,
计算出大减小的差
让用户输入自己计算的差
对比用户输入是否正确,正确提示“correct”,错误提示“wrong”

2、上题让用户连续做5题,统计对错各几题,然后结束程序
3、用户连续做对5题,才结束程序,统计用户共用时多少秒

package week2;

import java.util.Scanner;

public class yyykyy {
	public static void main(String[] args) {
		int i, x = 0, y = 0;
//		for (i = 1; i <= 100; i++) {
//			System.out.print((char) (65 + (int) (Math.random() * 26)) + " ");
//			if (i % 10 == 0)
//				System.out.println("");
//		}               //随机输出四位大写字母的验证码
		for (i = 1; i <= 5; i++) {
			int n, m, a;
			n = 60 + (int) (Math.random() * 41);
			m = 60 + (int) (Math.random() * 41);
			a = n + m;
			System.out.print(m + " + ");
			System.out.println(n);
			System.out.print("please input the result : ");
			Scanner input = new Scanner(System.in);
			int result = input.nextInt();
			if (result == a) {
				System.out.println("you r correct!!!");
				x += 1;
			} else {
				System.out.println("you r wrong!!!");
				y += 1;
			}
		}
		System.out.println("right result : " + x);
		System.out.println("wrong result : " + y);

	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值