Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Can't get application to run in Eclipse

Writer Emily Wong

I have the below code put in Eclipse, and I cannot get Eclipse to let me run it as a Java application. I was able to do so on the computer on which I wrote it, but I've tried twice since on two different computers and neither has the option. I've tried to set a manual configuration to do it and I've tried Alt+Shift+X, but neither worked. I can run Java applications on all of these computers normally, just not this one for some reason.

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(); }
}
2

1 Answer

Have you clicked with the right button and choose "run as" option, Java Application? It should work just fine in any environment.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy