我编译,然后在java.exe中运行这一段代码,我收到一个错误 [英] I compile and then run this bit of code in java.exe and i receive an error

查看:152
本文介绍了我编译,然后在java.exe中运行这一段代码,我收到一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚这段代码有什么问题。 Eclipse告诉我main方法没有声明。当我在java.exe中运行它时,它告诉我找不到或加载主类discount.java我花了最后一个半小时寻找一个解决方案,但似乎不能弄清楚。

I can't seem to figure out what is wrong with this code. Eclipse tells me main method isn't declared. and when I run it in java.exe it tells me "could not find or load main class discount.java" I've spent the last half hour looking for a solution but can't seem to figure it out.

import java.util.Scanner;

    public class Discount
    {
      public static void main (String[] args) 
      {
        Scanner scan = new Scanner( System.in );
        int price;

        System.out.println("Enter the Price:");
        price = scan.nextInt();


        System.out.println( price / 4 * 3  );
      }
    }

我使用的命令和错误获取:

The commands I'm using and error I'm getting:

> CD C:\Programing\Misc
> set path=%path%;C:\Program Files\Java\jdk1.8.0\bin
> javac discount.java
> java discount.java
Error: Could not find out or load main class java.discount 


推荐答案

您是否使用 java discount.java ?这可能是个问题。

Are you using java discount.java? That's likely the issue.

尝试这两行:

javac discount.java
java discount

这应该运行你的main方法(假设你正确地命名了文件discount.java)。

That should run your main method (assuming that you've correctly named the file discount.java).

-

EDIT :在看到您关于更改课程名称的评论后,想将文件重命名为Discount.java。然后运行 javac Discount.java java Discount

EDIT: After seeing your comment about changing the class name, you'll want to rename the file to Discount.java. Then run javac Discount.java and java Discount

这篇关于我编译,然后在java.exe中运行这一段代码,我收到一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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