JavaHomeWorkList
3.17 关键词:剪刀石头布;随机数
1 import java.util.Scanner;
2 public class JSB {
3 public static void main(String[] args) {
4 int a = (int)(Math.random() * 3);
5 Scanner input = new Scanner(System.in);
6 System.out.println("输入0(剪刀)/1(石头)/2(布):");
7 int x = input.nextInt();
8
9 if (x != 0 && x != 1 && x != 2)
10 System.out.println("请输入0/1/2!");
11 else {
12 if (a == 0 && x == 2)
13 System.out.println("电脑是剪刀,你是布,电脑赢!");
14 if (a == 1 && x == 0)
15 System.out.println("电脑是石头,你是剪刀,电脑赢!");
16 if (a == 2 && x == 1)
17 System.out.println("电脑是布,你是石头,电脑赢!");
18 if (a == 0 && x == 1)
19 System.out.println("电脑是剪刀,你是石头,你赢!");
20 if (a == 1 && x == 2)
21 System.out.println("电脑是石头,你是布,你赢!");
22 if (a == 2 && x == 0)
23 System.out.println("电脑是布,你是剪刀,你赢!");
24 if (a == x)
25 System.out.println("平手!");
26 System.out.println("电脑是:" + a);
27 }
28 input.close();
29 }
30
31 }
3.16 关键词:矩形;随机坐标;中心点(0,0)、宽100、高200
1 public class rectangle {
2 public static void main(String[] args) {
3 int x = (int)(Math.random() * 101 - 50);
4 int y = (int)(Math.random() * 201 - 100);
5 System.out.println("矩形内随机坐标为:" + "(" + x + " , " + y + ")");
6
7 }
8
9 }
3.14 关键词:硬币;正面;反面;0;1
1 import java.util.Scanner;
2 public class guesscoin {
3 public static void main(String[] args) {
4 int coin = (int)(Math.random() * 2);
5 Scanner input = new Scanner(System.in);
6 System.out.println("输入0或1,1代表正面,0代表反面:");
7 int guess = input.nextInt();
8
9 if (guess != 0 && guess != 1)
10 System.out.println("请输入0或1!");
11 else {
12 if (guess == coin)
13 System.out.println("猜对了!");
14 else
15 System.out.println("猜错了!");
16 System.out.println("硬币数字为:" + coin + " ;* 1代表正面,0代表反面");
17 }
18 input.close();
19 }
20 }
3.9 关键词:ISBN-10;检验和
1 import java.util.*;
2 public class ISBN10 {
3 public static void main(String[] args) {
4 Scanner input = new Scanner(System.in);
5 System.out.println("输入9个数字:");
6
7 int d1 = input.nextInt();
8 int d2 = input.nextInt();
9 int d3 = input.nextInt();
10 int d4 = input.nextInt();
11 int d5 = input.nextInt();
12 int d6 = input.nextInt();
13 int d7 = input.nextInt();
14 int d8 = input.nextInt();
15 int d9 = input.nextInt();
16
17 int sum = (int)(d1 * Math.pow(10, 8) + d2 * Math.pow(10, 7) + d3 * Math.pow(10, 6) + d4 * Math.pow(10, 5) + d5 * Math.pow(10, 4) + d6 * Math.pow(10, 3) + d7 * Math.pow(10, 2) + d8 * Math.pow(10, 1) + d9);
18
19 int d10 = (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11;
20 System.out.println("校验和为: " + d10);
21
22 if (d1 == 0)
23 if (d10 == 10)
24 System.out.println("ISBN-10为:" + "0" + sum + "X");
25 else
26 System.out.println("ISBN-10为:" + "0" + sum + d10);
27 else
28 System.out.println("ISBN-10为:" + sum * 10 + d10);
29 input.close();
30
31 }
32
33 }
3.8 关键词:非降序
1 import java.util.*;
2 public class NodescendingOeder {
3 public static void main(String[] args) {
4 Scanner input = new Scanner(System.in);
5 System.out.println("输入三个整数:");
6 int num1 = input.nextInt();
7 int num2 = input.nextInt();
8 int num3 = input.nextInt();
9 /*非降序列:通常非降序列的元素定义在有序域上,每一项不小于它的前一项。非降序列通常指无穷序列。
10 例如:定义在实数域上的非降序列 1,2,3,4,5,...6
11 非降序列每项不一定严格大于它的前一项,例如 1,1,1,1,1,...
12 */
13 if (num1 < num2) {
14 if (num1 < num3) {
15 System.out.print(num1);
16 if (num2 < num3)
17 System.out.print(" " + num2 + " " + num3);
18 else
19 System.out.print(" " + num3 + " " + num2);
20 }
21 else
22 System.out.print(num3 + " " + num1 + " " + num2);
23 }
24 else if (num1 < num3)
25 System.out.print(num2 + " " + num1 + " " + num3);
26 else if (num2 < num3)
27 System.out.print(num2 + " " + num3 + " " + num1);
28 else
29 System.out.print(num3 + " " + num2 + " " + num1);
30 input.close();
31 }
32 }
3.5 关键词:找到将来的日期
1 import java.util.*;
2 public class FindFutureDay {
3 public static void main(String[] args) {
4 Scanner input = new Scanner(System.in);
5 System.out.println("输入一个数字,周日是0,周一是1,... 周六是6 ");
6 int day0 = input.nextInt();
7 System.out.println("输入一个数字,表示天数: ");
8 int day1 = input.nextInt();
9 int futureday = ( day0 + day1 ) % 7;
10 //System.out.println("Today is " + day0 + " Futureday is " + futureday); 这个语句太粗糙!!!
11 switch (day0) {
12 case 0: System.out.print("Today is Sunday and the future day is "); break;
13 case 1: System.out.print("Today is Monday and the future day is "); break;
14 case 2: System.out.print("Today is Tuesday and the future day is "); break;
15 case 3: System.out.print("Today is Wendesday and the future day is "); break;
16 case 4: System.out.print("Today is Thursday and the future day is "); break;
17 case 5: System.out.print("Today is Friday and the future day is "); break;
18 case 6: System.out.print("Today is Saturday and the future day is ");
19 }
20
21 switch (futureday) {
22 case 0: System.out.print("Sunday "); break;
23 case 1: System.out.print("Monday "); break;
24 case 2: System.out.print("Tuesday "); break;
25 case 3: System.out.print("Wendesday "); break;
26 case 4: System.out.print("Thursday "); break;
27 case 5: System.out.print("Friday "); break;
28 case 6: System.out.print("Saturday ");
29 }
30 //双重switch语句
31 input.close();
32
33 }
34
35 }
3.11 关键词:一个月的总天数
1 import java.util.*;
2 public class DaysOfMonth {
3 public static void main(String[] args) {
4 // TODO Auto-generated method stub
5 Scanner input = new Scanner(System.in);
6 System.out.println("Enter a month and a year: ");
7 int month = input.nextInt();
8 int year = input.nextInt();
9
10 /*if (month ==2)
11 if ((year % 4 == 0 && year % 100 != 0) || year % 400 ==0)
12 System.out.println("February of " + year + " has" + " 29 days ");
13 else
14 System.out.println("February " + year + " has" + " 28 days ");
15 else if (month == 1 ||month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
16 System.out.println(month + " of " + year + " has 31 days ");
17 else
18 System.out.println(month + " of " + year + " has 30 days ");
19 */
20 if ((year % 4 == 0 && year % 100 != 0) || year % 400 ==0)
21 switch(month) {
22 case 1:System.out.println("Jan. " + year + " has 31 days."); break;
23 case 2:System.out.println("Feb. " + year + " has 29 days."); break;
24 case 3:System.out.println("Mar. " + year + " has 31 days."); break;
25 case 4:System.out.println("Apr. " + year + " has 30 days."); break;
26 case 5:System.out.println("May. " + year + " has 31 days."); break;
27 case 6:System.out.println("Jun. " + year + " has 30 days."); break;
28 case 7:System.out.println("Jul. " + year + " has 31 days."); break;
29 case 8:System.out.println("Aug. " + year + " has 31 days."); break;
30 case 9:System.out.println("Sep. " + year + " has 30 days."); break;
31 case 10:System.out.println("Oct. " + year + " has 31 days."); break;
32 case 11:System.out.println("Nov. " + year + " has 30 days."); break;
33 case 12:System.out.println("Dec. " + year + " has 31 days.");
34 }
35 else
36 switch(month) {
37 case 1:System.out.println("Jan. " + year + " has 31 days."); break;
38 case 2:System.out.println("Feb. " + year + " has 28 days."); break;
39 case 3:System.out.println("Mar. " + year + " has 31 days."); break;
40 case 4:System.out.println("Apr. " + year + " has 30 days."); break;
41 case 5:System.out.println("May. " + year + " has 31 days."); break;
42 case 6:System.out.println("Jun. " + year + " has 30 days."); break;
43 case 7:System.out.println("Jul. " + year + " has 31 days."); break;
44 case 8:System.out.println("Aug. " + year + " has 31 days."); break;
45 case 9:System.out.println("Sep. " + year + " has 30 days."); break;
46 case 10:System.out.println("Oct. " + year + " has 31 days."); break;
47 case 11:System.out.println("Nov. " + year + " has 30 days."); break;
48 case 12:System.out.println("Dec. " + year + " has 31 days.");
49 }
50 input.close();
51 }
52
53 }
练习题,关键词:彩票
1 import java.util.Scanner;
2 public class caipiao {
3 public static void main(String[] args) {
4 int cp = (int)(Math.random() * 100);//获取一个两位数的数字作为彩票号码
5
6 Scanner input = new Scanner(System.in);
7 System.out.println("输入你猜测的彩票号码:");
8 int guess = input.nextInt();
9
10 int cp1 = cp / 10;
11 int cp2 = cp % 10;
12
13 int guess1 = guess / 10;
14 int guess2 = guess % 10;
15
16 System.out.println("彩票号码是:" + cp);
17
18 if (guess == cp)
19 System.out.println("恭喜你猜对了,你将获得100元!");
20 else if (guess1 == cp2 && guess2 == cp2)
21 System.out.println("数字对了,顺序不对,你将获得50元!");
22 else if (guess1 == cp1 || guess1 == cp2 || guess2 == cp1 || guess2 == cp2)
23 System.out.println("猜对了一个数字,你将获得30元!");
24 else
25 System.out.println("很遗憾,你没有猜对!");
26 input.close();
27
28 }
29
30 }
JavaHomeWorkList的更多相关文章
随机推荐
- 地图开发笔记(一):百度地图介绍、使用和Qt内嵌地图Demo
前言 Qt在地图方面的研发. 百度地图 介绍 百度的地图分为多个开发,都是在线的(离线的需要自己提取,本篇解说在线地图). 百度地图JavaScript API支持HTTP和HTTPS, ...
- CS系统中分页控件的制作
需求:在一个已有的CS项目(ERP中),给所有的列表加上分页功能. 分页的几个概念: 总记录数 totalCount (只有知道了总记录数,才知道有多少页) 每页记录数 pageSize (根据总 ...
- 用隧道协议实现不同dubbo集群间的透明通信
用隧道协议实现不同dubbo集群间的透明通信 前言 笔者最近完成了一个非常有意思的隧道机制(已在产线运行),可以让注册到不同zookeeper之间的dubbo集群之间能够正常进行通信.如下图所示: 例 ...
- 转载-Oracle 数据库导入导出 dmp文件
首先询问对方数据库的表空间名称和大小,然后在你的oracle中建立相应表空间,最后使用命令导入.导出数据.补充:1.要新建一个数据库: Oracle数据导入导出imp/exp就相当于oracle数据还 ...
- PAT甲级练习 1087 All Roads Lead to Rome (30分) 字符串hash + dijkstra
题目分析: 这题我在写的时候在PTA提交能过但是在牛客网就WA了一个点,先写一下思路留个坑 这题的简单来说就是需要找一条最短路->最开心->点最少(平均幸福指数自然就高了),由于本题给出的 ...
- requests+BeautifulSoup | 爬取电影天堂全站电影资源
import requests import urllib.request as ur from bs4 import BeautifulSoup import csv import threadin ...
- 【Nginx】配置nginx图片服务器
想通过nginx来访问服务器上的图片 可以搭建一个nginx图片服务器. 做法如下: 先安装nginx,这里直接用yum来进行安装的 安装方法如下: https://blog.csdn.net/iml ...
- 【Oracle】10.2.0.1升级到10.2.0.5
升级数据库到10.2.0.5 因是测试环境,不需要备份:如是生产系统,建议进行全备份后再进行升级操作,预防数据丢失造成不必要的影响. 步骤: 上传并解压补丁,安装前准备,安装补丁,预升级检查, ...
- CTFHub - Misc(流量分析)
数据库类流量: MySQL流量: 1.下载附件,是一个.pcap文件,用wireshark分析, 2.搜索ctfhub字段,即可得到flag, flag: ctfhub{mysql_is_S0_E4s ...
- CodeMonkey少儿编程第2章 turnTo对象
目标 了解对象的概念 了解方法与对象的关系 掌握turnTo指令的用法 在开始本章的学习之前,我们先来复习一下上一章的知识点. 在第1章中,我们学会了在这个游戏中最简单的两个指令. step x 其中 ...