expected"Java 编译错误-6ren"> expected"Java 编译错误-我在这一行收到“ expected ”错误...... private static String getReducedISBN(char 'x') { ...这段代码.... public cl-6ren">
gpt4 book ai didi

java - " expected"Java 编译错误

转载 作者:行者123 更新时间:2023-12-01 07:14:47 25 4
gpt4 key购买 nike

我在这一行收到“<identifier> expected ”错误......

  private static String getReducedISBN(char 'x') {

...这段代码....

public class CheckISBN7 {

//private static String originalISBN; // class variable

public static void main(String[] args) {
// Prompt the user to enter an ISBN
SimpleIO.prompt("Enter ISBN: ");
String originalISBN = SimpleIO.readLine();

// Get the ISBN number without the dashes
String reducedISBN = getReducedISBN('-');

// Get the computed check digit
int computedCheckDigit = getCheckDigit(reducedISBN);

// Display check digit entered by the user
System.out.println("Check digit entered: " + originalISBN.charAt(12));

// Display computed check digit
System.out.println("Check digit computed: " + computedCheckDigit);
}

private static String getReducedISBN(char 'x') {
SimpleIO.prompt("Enter ISBN: ");
String originalISBN = SimpleIO.readLine();
int dashPos1 = originalISBN.indexOf("x");
int dashPos2 = originalISBN.indexOf("x", dashPos1 + 1);
String reducedISBN = originalISBN.substring(0, dashPos1) +
originalISBN.substring(dashPos1 + 1, dashPos2) +
originalISBN.substring(dashPos2 + 1, 11);
return reducedISBN;
}

private static int getCheckDigit(String reducedISBNParameter) {
int total = 0;
final String digits = "0123456789X";
for(int i = 0, j = 10; i <= 8; i++, j++) {
total += j *
(Integer.parseInt(reducedISBNParameter.substring(i, i + 1)));
}
int checkDigit = 10 - ((total - 1) % 11);
int computedCheckDigit = digits.charAt(checkDigit);
return computedCheckDigit;
}
}

无法真正找出问题,任何帮助将不胜感激。

最佳答案

'x' 不是一个标识符(变量或其他),它是一个文字字符。同样,“x”是一个文字字符串。将 char 'x' 替换为 Character x,将 "x" 替换为 x.toString() 即可得到您想要的内容想要。

关于java - "<identifier> expected"Java 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com