我正在尝试使用此字符串
amountStr = amountStr.replace("$", "").replace(" ", "").replace(",", "");
但是我收到一条错误消息,我知道我得到了因为我刚刚发布的字符串已经过时了。所以我想知道该字符串的更新版本是什么?这是我的整个代码的样子。
import java.util.Scanner;
public class QuarterMachine{
/**
* Convert the input to cents.
*/
public static void main(String[] args){
// PART I INPUT SECTION (COMPLETE)
// DO NOT CHANGE THESE LINES
Scanner cin = new Scanner(System.in);
System.out.print("Part I-Enter the amount input ($ 1,572.52): ");
String amountStr = cin.nextLine();
// PLACE YOUR CODE ONLY BELOW THIS LINE
// PLACE YOUR OUTPUT IN THESE VARIABLES
// ---------- YOUR CHANGES HERE ----------------------
double amount = 0;
int quarters = 0;
//My problem is in line below
amountStr = amountStr.replace("$", "").replace(" ", "").replace(",", "");
amount = Double.parseDouble(amountStr);
quarters = (int) (amount * 100) / 25;
// PLACE YOUR CODE ONLY ABOVE THIS LINE
// PART I OUTPUT SECTION COMPLETE
System.out.printf("Amount received($%,.0f), quarters returned(%,d)%n%n",amount, quarters);
// PART II INPUT SECTION (COMPLETE)
System.out.print("Part II-Enter seconds, minutes and hours as integers: ");
int seconds = cin.nextInt();
int minutes = cin.nextInt();
int hours = cin.nextInt();
// PLACE YOUR CODE ONLY BELOW THIS LINE
// PLACE YOUR OUTPUT IN THIS VARIABLE
String result = String.format("%02d:%02d:%02d", hours, minutes, seconds);
// YOUR CODE MUST GO ABOVE THIS LINE
// PART II - OUTPUT SECTION COMPLETE
System.out.println("Result: " + result);
}
}
答案 0 :(得分:4)
我认为这是Eclipse中的某种错误。您可以通过尝试下面写的每个解决方案来解决此问如果一个人没有工作,请尝试下一个。
希望这有帮助。
答案 1 :(得分:0)
升级到JDK 8后可能会遇到此错误,因为一些旧接口现在在1.8中有新的默认方法。
希望这会有所帮助