Java语言基础知识之习题二
题目见图片附件Seven:
import java.util.Scanner;
public class Seven {
static int user1, user2;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请玩家1输入石头、剪刀或者布:");
String a = sc.nextLine();
System.out.println("请玩家2输入石头、剪刀或者布:");
String b = sc.nextLine();
user1 = exchange(a, user1);
user2 = exchange(b, user2);
check(user1, user2);
}
private static void check(int user1, int user2) {
if (user1 == user2) {
System.out.println("平局");
return;
}
if (user1 == 0) {
if (user2 == 2) {
System.out.println("玩家1Win");
} else {
System.out.println("玩家2Win");
}
} else if (user1 == 2) {
if (user2 == 0) {
System.out.println("玩家2Win");
} else {
System.out.println("玩家1Win");
}
} else if (user1 == 5) {
System.out.println("玩家2Win");
} else {
System.out.println("玩家1Win");
}
}
private static int exchange(String x, int n) {
if ("剪刀".equals(x)) {
n = 2;
} else if ("石头".equals(x)) {
n = 0;
} else {
n = 5;
}
return n;
}
}
Eight:
public class Corporation {
double salary;
int hour;
public Corporation(double salary, int hour) {
this.salary = salary;
this.hour = hour;
}
void getMoney() {
if (this.salary < 8.0 || this.hour > 60) {
System.out.println("Declined to 996");
return;
}
double m = this.hour * this.salary;
if (this.hour <= 40) {
System.out.println(m);
} else {
System.out.println(m + (this.hour - 40 * 1.5));
}
}
}
public class Main {
public static void main(String[] args) {
Corporation user1 = new Corporation(7.50,35);
Corporation user2 = new Corporation(8.20,47);
Corporation user3 = new Corporation(10.00,73);
user1.getMoney();
user2.getMoney();
user3.getMoney();
}
}
Nine:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Nine {
public static void main(String[] args) throws IOException {
System.out.println("请输入个数及其差值");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
int cnt = Integer.parseInt(s);
int dif = Integer.parseInt(s);
System.out.println("输入" + cnt +"个整数");
String[] s1 = br.readLine().split(" ");
int [] arr = new int;
for(int i = 0 ;i<arr.length;i++){
arr = Integer.parseInt(s1);
}
for(int i = 0;i<arr.length-1;i++){
if (Math.abs(arr - arr) >dif){
System.out.println("数列从" + ++i + "个数开始中断");
return;
}
}
System.out.println("这是" + cnt + "个数组组成的连续数列,差值为" + dif );
}
}
在新标签打开所有链接复制所有链接URL复制所有链接URL(反向)复制所有链接标题 + URL复制所有链接标题 + URL (MD)复制所有链接标题 + URL (BBS)复制所有链接标题 + URL (筛选)复制所有链接标题 + URL (设置复制格式)在新标签页打开所有图片链接在一个标签页显示所有图片链接
复选框 - 选中
复选框 - 取消
复选框 - 反选
单选框 - 选中
单选框 - 取消
特殊单选框 - 选中 学习一下 谢谢分享 谢谢楼主分享 谢楼主分享,支持一下!{:17_1089:} 学习学习!!!!!!!!
页:
[1]