Ich schreibe ein Programm in Java, das den Benutzer nach einem Angestelltennamen und dem Gehalt fragt. Ich muss ein Nummernzeichen vor das Gehalt setzen, sobald es eingegeben und auf dem Bildschirm angezeigt wird. Irgendeine Idee, wie ich das machen würde?Wie man ein Nummernzeichen an eine Nummer anfügt
Vielen Dank im Voraus!
public static void main(String[] args) {
//use default constructor
//ask name
String name = JOptionPane.showInputDialog("What is Employee #1's name?");
//System.out.println(name);
//ask salary
double salary = Double.parseDouble(JOptionPane.showInputDialog("What is the employee's salary?"));
//System.out.print(salary);
//make an employee1 value
Employee employee1 = new Employee(name, salary);
//print out
System.out.println(employee1);
System.out.printf("Employee: %s%n", employee1.getName());
System.out.printf("Salary: %.3f%n", employee1.getSalary());
// System.out.printf("Employee: %s", employee1.getName());
JOptionPane.showMessageDialog(null, "This is the Employee's name:" + employee1.getName());
JOptionPane.showMessageDialog(null, "This is the Employee's salary:" + employee1.getSalary());
System.out.printf("%.3f", salary);
//employee 2
String name1 = JOptionPane.showInputDialog("What is Employee #2's name?");
double salary1 = Double.parseDouble(JOptionPane.showInputDialog("What is the employee's salary?"));
//System.out.print(salary);
//make an employee2 value
Employee employee2 = new Employee(name1, salary1);
//print out
System.out.println(employee2);
System.out.printf("Employee: %s%n", employee2.getName());
System.out.printf("Salary: %.3f%n", employee2.getSalary());
// System.out.printf("Employee: %s", employee2.getName());
JOptionPane.showMessageDialog(null, "This is the Employee's name:" + employee2.getName());
JOptionPane.showMessageDialog(null, "This is the Employee's salary:" + employee2.getSalary());
System.out.printf("%.3f", salary);
}
}
System.out.printf ("Gehalt: #% .3f% n", employee2.getSalary()); ? –
nummer zeichen, was es bedeutet? Suchst du nach Währung simbol? –
Was ist ein "Nummernzeichen"? Währungszeichen? Haben Sie es einfach als Teil Ihrer Prtinf-Saite? –