简单写了一下:
import java.util.*;
public class test {
public static void reverseString(String str) {
if (str.length() == 1) {
System.out.print(str);
} else {
String subString1 = str.substring(0, str.length() - 1);
String subString2 = str.substring(str.length() - 1);
System.out.print(subString2);
reverseString(subString1);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("你想不想做题");
String s = scanner.next();
if (!s.equals("想")) {
return;
}
System.out.println("--------------------------");
while (true) {
System.out.println("你想做数学还是统计还是美术还是附加题还是附加题2?");
s = scanner.next();
if (s.equals("数学")) {
System.out.println("67-43等于多少");
Integer i = scanner.nextInt();
if (i == (67 - 43)) {
System.out.println("你答对了");
} else {
System.out.println("你答错了");
}
} else if (s.equals("统计")) {
System.out.println("你会不会做统计?");
s = scanner.next();
if (!s.equals("会")) {
break;
}
System.out.println("请输入学生的成绩,输入-1则终止程序");
Integer i;
List list = new ArrayList();
Integer sum = 0;
do {
i = scanner.nextInt();
if (i != -1) {
list.add(i);
}
sum = sum + i;
} while (i != -1);
System.out.println("结束输入");
System.out.println("学生和数为" + list.size());
System.out.println("最高分为" + Collections.max(list));
System.out.println("最低分为" + Collections.min(list));
System.out.println("平均分为" + sum / list.size());
} else if (s.equals("美术")) {
System.out.println("美术题:你要写三角形还是菱形还是平行四边形");
s = scanner.next();
if (s.equals("三角形")) {
for (int i = 1; i <= 5; i++) {
for (int j = 5; i <= j; j--)
System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print("*");
for (int j = 1; j < i; j++)
System.out.print("*");
System.out.println();
}
} else if (s.equals("菱形")) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5 - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print('*');
}
System.out.println();
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * (4 - i + 1) - 1; k++) {
System.out.print('*');
}
System.out.println();
}
} else if (s.equals("平行四边形")) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4 - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 6; j++) {
System.out.print("*");
}
System.out.println();
}
} else {
System.out.println("输入错误");
}
} else if (s.equals("附加题")) {
System.out.println("附加题:将一个整数倒序");
System.out.println("请输入一个数");
s = scanner.next();
System.out.print("输出结果为 ");
reverseString(s);
} else if (s.equals("附加题2")) {
System.out.println("现在你可以拥有自己的柜子,存放自己的物品");
System.out.println("你需要多少个柜子存放物品?");
Integer i = scanner.nextInt();
List<String> list = new ArrayList();
for (int j = 1; j <= i; j++) {
System.out.println("请输入你要在第" + j + "个箱子里存放的物品");
String item = scanner.next();
list.add(item);
System.out.println("你在第" + j + "个箱子里放了" + item);
}
for (int j = 1; j <= i; j++) {
System.out.println("你取出了第" + j + "个柜子内的物品,物品为" + list.get(j - 1));
}
} else {
System.out.println("输入不正确");
}
}
}
}