public static void main(String[] args) throws FileNotFoundException
{
printHeading();
Scanner file1 = new Scanner(new File("C:\\Users\\nupur\\workspace\\Project2\\src\\EmployeesIn.dat")) ;
System.out.println("New Employee added: Pryce, Lane");
System.out.println("New Wages: ");
while(file1.hasNextLine())
{
double total =0;
String line=file1.nextLine();
Scanner lineData = new Scanner(line);
String name = lineData.next().trim();
int comma = name.indexOf(',');
String last = name.substring(0, comma);
String first = lineData.next().trim();
char status = (lineData.next().trim()).charAt(0);
double wage = Double.parseDouble((lineData.nextLine().trim()));
它给了我这个错误:新工资:
Exception in thread "main" java.lang.NumberFormatException: For input string: "5.00Baird, Joey h 7.50Kinsey, Paul h 8.00Olson, Margaret s 15000Campbell, Peter s 20000Draper, Donald s 40000Sterling, Roger s 45000Cooper, Bertram s 50000"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at Project2.main(Project2.java:38)
这一切都很混乱。
你如何做这样的事情:
public static void main(String[] args) throws FileNotFoundException {
printHeading();
Scanner file1 = new Scanner(new File("C:\\Users\\nupur\\workspace\\Project2\\src\\EmployeesIn.dat")) ;
System.out.println("New Employee added: Pryce, Lane");
System.out.println("New Wages: ");
while(file1.hasNextLine()) {
System.out.println("Wage = " + file1.nextLine().replaceAll("[\\D]", "")) //replace all non-digit characters with blank
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句