gpt4 book ai didi

java - 如何在小程序中运行该程序?

转载 作者:行者123 更新时间:2023-12-02 05:49:13 26 4
gpt4 key购买 nike

package Homework;

import java.util.Scanner;

class FantasyGame{

public static void main ( String args[])

{
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to Supercalifragilisticexpialidocious Quest!");
System.out.println("Enter the name of your character: ");
String name;
name = scan.nextLine();
System.out.println("Welcome to Supercalifragilisticexpialidocious Quest, " + (name) + "! " + "You will now assign attributes to your character, the total value assigned must not exceed 15 or be under 0, or the points will be assigned by default! (Type any NUMBER to continue)");
int ans = scan.nextInt();
System.out.println("Enter Strength (0-15): ");
int str = scan.nextInt();
System.out.println("Enter Health (0-15): ");
int hp = scan.nextInt();
System.out.println("Enter Luck (0-15): ");
int lck = scan.nextInt();
if (str + hp + lck <= 15)
{
System.out.println("Congratulations! You have successfully created your character!");
System.out.println("Name: " + (name));
System.out.println("Strength: " + (str));
System.out.println("Health: " + (hp));
System.out.println("Luck: " + (lck));
}

if (str + hp + lck > 15)
{
System.out.println("You have give your character too many attribute points! Default values have been assigned.");
System.out.println("Name: " + (name));
System.out.println("Strength: " + (5));
System.out.println("Health: " + (5));
System.out.println("Luck: " + (5));
}


}

}

我想为我的历史课制作一个基于文本的游戏,我知道基本的 Java 足以制作一个只有变量和东西的小游戏,但我不知道如何制作它,以便它直接作为具有黑色背景和白色文本的小程序,它会显示并响应您键入的内容,就像上面的代码在控制台中所做的那样。

我尝试过命令提示符方法,但得到的只是“访问被拒绝”。

另外,当我尝试在 Eclipse 中导出时,启动配置总是转到我不想要的类。抱歉,我真的很困惑,需要很多帮助。

最佳答案

编写一个简单的小程序,http://docs.oracle.com/javase/tutorial/deployment/applet/ Oracle 的这个教程将很好地引导您完成它,那么重新排列您的代码应该不会太难

关于java - 如何在小程序中运行该程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23732994/

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