
import java.util.Scanner
/*输入一个成绩,将该成绩转换为A、B、C、D和E:成绩在90分以上,结果为A,成绩在80-90之间纤裤,结果为B,成绩在70-80之间,结果为C,成绩在60-70之间,结果为D,庆敏成绩在60分以下,结果为E。*/
public class Chengfabiao
{
public static void main (String[] args)
{
Scanner scanner 誉竖枝= new Scanner(System.in)
int score = scanner.nextInt()
if(score>90)
{
System.out.println("A")
}
else if(score>=80)
{
System.out.println("B")
}
else if(score>=70)
{
System.out.println("C")
}
else if(score>=60)
{
System.out.println("D")
}
else
{
System.out.println("E")
}
}
}
import java.util.Random
import java.util.Scanner
public class T {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in)
int difficulty//难度
int mode//运算类型
int answer//答案
int amount//挑战题目数量橘伍
int score = 0//得分
System.out.println("请输入难度(1:一位数、2:圆腊或两位数、3:局尺三位数):")
difficulty = in.nextInt()
System.out.println("请输入运算类型(1:加、2:减、3:乘、4:除):")
mode = in.nextInt()
System.out.println("请输入想要挑战的题目数量:")
amount = in.nextInt()
Random random = new Random()
for (int i = 0i <amounti++) {
if (difficulty == 1) {
if (mode == 1) {
int x = random.nextInt(10)
int y = random.nextInt(10)
System.out.println("第" + i + "题:")
System.out.print(x + " + " + y + " = ")
answer = in.nextInt()
if (answer == (x + y)) {
System.out.println("答对了\n")
score++
} else {
System.out.println("答错了,答案是:" + (x + y) + "\n")
}
} else if (mode == 2) {
int x = random.nextInt(10)
int y = random.nextInt(10)
System.out.println("第" + i + "题:")
System.out.print(x + " - " + y + " = ")
answer = in.nextInt()
if (answer == (x - y)) {
System.out.println("答对了\n")
score++
} else {
System.out.println("答错了,答案是:" + (x - y) + "\n")
}
} else if (mode == 3) {//乘法
} else if (mode == 4) {//除法 考虑小数的问题
} else {
throw new Exception("运算类型输入值不合法")
}
} else if (difficulty == 2) {
if (mode == 1) {
int x = random.nextInt(100)
int y = random.nextInt(100)
System.out.println("第" + i + "题:")
System.out.print(x + " + " + y + " = ")
answer = in.nextInt()
if (answer == (x + y)) {
System.out.println("答对了\n")
score++
} else {
System.out.println("答错了,答案是:" + (x + y) + "\n")
}
} else if (mode == 2) {
} else if (mode == 3) {//乘法
} else if (mode == 4) {//除法 考虑小数的问题
} else {
throw new Exception("运算类型输入值不合法")
}
} else if (difficulty == 3) {
if (mode == 1) {
int x = random.nextInt(1000)
int y = random.nextInt(1000)
System.out.println("第" + i + "题:")
System.out.print(x + " + " + y + " = ")
answer = in.nextInt()
if (answer == (x + y)) {
System.out.println("答对了\n")
score++
} else {
System.out.println("答错了,答案是:" + (x + y) + "\n")
}
} else if (mode == 2) {
} else if (mode == 3) {//乘法
} else if (mode == 4) {//除法 考虑小数的问题
} else {
throw new Exception("运算类型输入值不合法")
}
} else {
throw new Exception("难度输入值不合法")
}
}
System.out.println("挑战结束,您的分数为:" + score)
}
}
我就只举了加法的例子,其他运算的写法都是类似的,你照葫芦画瓢即可
运行结果:
public class Test {public static void main(String[] args) {
// 定义数组
int[][] array = new int[5][6]
// 生成随机数初始化数组
for (int i = 0 i < array.length i++) {
for (int j = 0 j < array[i].length j++) {
拆闹array[i][j] = (int) (40 * Math.random()) + 10
}
}
旅拿罩 敏戚// 输出数组
for (int i = 0 i < array.length i++) {
for (int j = 0 j < array[i].length j++) {
System.out.print(array[i][j] + "\t")
}
System.out.println() // 换行
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)