gpt4 book ai didi

java - 尝试使用数据创建菜单

转载 作者:行者123 更新时间:2023-12-01 23:48:34 25 4
gpt4 key购买 nike

我正在尝试使用我从另一篇文章中看到的数据 Creating a console menu for user to make a selection创建一个菜单,用户可以在其中选择一个选项。当我运行我的程序时,它会抛出几个错误。也许我没有正确导入它,但这是唯一的方法我能想到。

import java.util.Random;
import java.util.Data;
public class Main{
public static void main(String[] args) {
System.out.println("Please enter 1 if you'd like to guess the computer's number or enter 2 to have the computer guess your number. If 2, please enter a number between 1-100 after you enter 2. ");
Data data = new Data();
data.menu();

Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();

switch (choice) {
case 1:
double r = (Math.random()*((100-1)+1))+min;

int win = 0;
while (win != 1);
System.out.println("The computer has guessed a number, please make a guess. ");
int u1 = scanner.nextInt();
if (r > u1)
System.out.println("Too low.");
else if (r < u1)
System.out.println("Too high.");
else if (r == u1){
System.out.println("You guessed it!!!!!!! Congratulations!!!!!!!!!!");
int win = win + 1 ;}
else
System.out.println();
break;
case 2:
System.out.println("You'd like myself, the computer to guess huh, well be prepared to get destroyed!");
int un = scanner.nextInt();
if (un == 36){
System.out.println("Chandler I told you not to!!!!!!");
break;}
else
System.out.println();

System.out.println("Your number is " + un);
break;


default:
System.out.println("You weren't supposed to do that!!!! Stop the program and run it again. Congrats! You broke it! Chandler, if you entered 36, ");
TimeUnit.SECONDS.sleep(5);
System.out.print("you've been banned!");
}

}

}

最佳答案

所有编译器错误按顺序排列。

import java.util.Data; // Does not exist, @MadProgrammer is correct, causes error
Data data = new Data(); // Error, Data cannot be resolved as to a type

Scanner scanner = new Scanner(System.in); // You did not import java.util.Scanner.
// Scanner cannot be resolved to a type.

double r = (Math.random()*((100-1)+1))+min; // min cannot be resolved to a variable
// You didn't define it

System.out.println("The computer has guessed a number, please make a guess. ");
int win = win + 1 ;} // win was a variable that was previously defined. Just change it
from "int win =" to "win = "

TimeUnit.SECONDS.sleep(5); // Did you mean to import java.util.concurrent.TimeUnit;

此外,如果您想“禁止”某人使用您的程序,那么为什么不创建一个 .txt 文件来读取,这可以帮助您的程序记住它之前是否已被“破坏”。

关于java - 尝试使用数据创建菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58228530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com