MBTI完整java代码
时间: 2023-10-16 08:20:28 浏览: 58
由于MBTI测试涉及到用户输入和算法逻辑,这里提供一个简单的示例代码,但并不是完整的、可用的MBTI测试代码。该代码仅供参考,不能直接用于生产环境。
```java
import java.util.Scanner;
public class MBTI {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the MBTI personality test!");
// 问题集合
String[] questions = {
"1. You enjoy social events with lots of people, true or false?",
"2. You prefer to spend time alone or with a few close friends, true or false?",
// 以下省略
"10. You tend to be more logical than emotional, true or false?"
};
// 分数记录
int[] scores = new int[4];
// 遍历问题,让用户回答
for (String question : questions) {
System.out.println(question);
String answer = scanner.nextLine();
// 根据用户回答,更新分数记录
if (answer.equalsIgnoreCase("true")) {
scores[0]++;
} else {
scores[1]++;
}
if (answer.equalsIgnoreCase("yes")) {
scores[2]++;
} else {
scores[3]++;
}
}
// 根据分数计算MBTI类型
String[] type = new String[4];
type[0] = (scores[0] > scores[1]) ? "E" : "I";
type[1] = (scores[2] > scores[3]) ? "S" : "N";
// 以下省略
// 输出结果
String result = "Your MBTI type is: " + type[0] + type[1] + type[2] + type[3];
System.out.println(result);
}
}
```