我对编码很陌生,迄今为止只使用 bluej 来编写 java 代码。我想改用 IDEone 进行编码,这样我就可以从学校编程课上使用的计算机切换到我的家用计算机,而无需使用 USB 或其他设备将代码从一台计算机复制到另一台计算机。问题是我不知道如何在 IDEone 中编写程序。我有几个用 bluej 制作的程序,它们编译和执行得很好,但是当粘贴到 IDEone 中查看它是否可以工作时,我不断收到错误。这是其中一个代码的示例
import java.util.Scanner;
public class IncomeTaxCalculator{
public static void main(String [] args){
// Constants
final double TAX_RATE = 0.20;
final double STANDARD_DEDUCTION = 10000.0;
final double DEPENDENT_DEDUCTION = 2000.0;
Scanner reader = new Scanner(System.in);
double grossIncome;
int numDependents;
double taxableIncome;
double incomeTax;
// Request the inputs
System.out.print("Enter the gross income: ");
grossIncome = reader.nextDouble();
System.out.print("Enter the number of dependents: ");
numDependents = reader.nextInt();
//Compute the income tax
taxableIncome = grossIncome - STANDARD_DEDUCTION - DEPENDENT_DEDUCTION * numDependents;
incomeTax = taxableIncome * TAX_RATE;
//Display the income tax
System.out.println("The income TAX IS $" + incomeTax);
}
}
在 IDEone 中,这给了我错误: Main.java:3: error: class IncomeTaxCalculator is public, should be statements in a file named IncomeTaxCalculator.java
公共类所得税计算器{
在 IDEone 中启动程序的正确方法是什么?我该如何更改这个程序才能正确编译
这并不是 ideone 的真正设计目的。它旨在成为共享小代码片段的工具,例如用于在 StackOverflow 上发布。它并不意味着成为整个项目的 IDE。
在这种情况下,错误消息告诉您,ideone 在幕后将代码保存到文件中Main.java
所以它希望你的班级被命名Main
, not IncomeTaxCalculator
。或者,该类可以不公开。
以下是 Java 片段的 ideone 模板。它清楚地解释了要求:
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)