如何在 Eclipse 中运行一个简单的 Java 程序? [英] How to Run a Simple Java Program in Eclipse?

查看:19
本文介绍了如何在 Eclipse 中运行一个简单的 Java 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您可能从问题本身理解的那样,我是 Java 新手.我得到了一个练习来编写一个 Java 程序,该程序接收一个字符,打印它和 Unicode 表中的下一个字符.

As you can probably understand from the question itself, I'm new to Java. I was given an exercise to write a Java program which receives a character, prints it and the next character in the Unicode table.

现在,我有了这个练习的解决方案:

Now, I have the solution to this exercise:

public static void main(String[] args){
    char c = args[0].charAt(0);
    char c1 = (char)(c + 1);
    System.out.println(c + "	" + c1);
}

我了解这段代码的基本思想,但我试图在 Eclipse 中运行这段代码,我遇到了一个恼人的错误:

I understand basic idea of this code, but I'm trying to run this code in Eclipse I get an annoying error:

线程main"中的异常 java.lang.ArrayIndexOutOfBoundsException: 0在 MainClass.main(MainClass.java:9)

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at MainClass.main(MainClass.java:9)

注意:我还没有运行过一个实际接收一些东西作为参数的 Java 程序,所以我想这是一个愚蠢的初学者错误......这是我试图在 Eclipse 中编译的完整代码:

Note: I have yet to run a Java program that actually receives something as a parameter so I guess it's a stupid beginners' mistake... Here is the full code that I tried to compile in Eclipse:

public class MainClass {

    /**
     * @param args
     */

    public static void main(String[] args){
        char c = args[0].charAt(0);
        char c1 = (char)(c + 1);
        System.out.println(c + "	" + c1);
    }
}

提前致谢

推荐答案

  • 从菜单中选择运行 -> 运行配置".
  • 在左侧列表中搜索您的项目并选择它.
  • 选择右侧的参数"标签.
  • 在程序参数"中写入要传递给程序的参数.
  • 点击运行"
  • 这篇关于如何在 Eclipse 中运行一个简单的 Java 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆