我在 Eclipse 中放置了以下代码,但我无法让 Eclipse 让我将其作为 Java 应用程序运行。我可以在我编写它的计算机上这样做,但我已经尝试了两次,因为在两台不同的计算机上都没有这个选项。我尝试设置手动配置来执行此操作,并且尝试过Alt+Shift+X
,但都没有成功。我可以在所有这些计算机上正常运行 Java 应用程序,只是由于某种原因不能在这台计算机上运行。
import java.util.Scanner;
public class Donor {
public String name;
public int age;
public double donation;
Donor() {
//Initialized to these values for debugging
name = "NoName";
age = 0;
donation = 0;
}
Donor(String nameinit, int ageinit, double donationinit) {
name = nameinit;
age = ageinit;
donation = donationinit;
}
public String toString() {
String str = "";
str += String.format("%s-30%i-6$%d-20", name, age, donation);
return str;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String nameinit = null;
int ageinit = -1;
double donationinit = -1;
String outp = null;
System.out.print("Enter the donor's name: ");
nameinit = input.nextLine();
System.out.print("Enter the donor's age: ");
ageinit = input.nextInt();
System.out.print("Enter the donation amount: ");
donationinit = input.nextDouble();
Donor d = new Donor(nameinit, ageinit, donationinit);
outp = d.toString();
System.out.printf("%s30 %s6 %s10", "Name", "Age", "Donation");
System.out.print("\n" + outp);
input.close();
}
}