无法让应用程序在Eclipse中运行

时间:2012-09-15 18:26:03

标签: java eclipse

我在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();

    }

}

1 个答案:

答案 0 :(得分:0)

您是否单击了右键并选择“运行方式”选项,Java Application?它应该在任何环境下都能正常工作。