Issue
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();
}
}
Solution
Have you clicked with the right button and choose "run as" option, Java Application? It should work just fine in any environment.
Answered By - gdfbarbosa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.