我是Java的新手,我在这里遇到了这个问题.我会发布链接并记住,这里的其他类似问题对我没有帮助,因为我有不同的代码,因此我在这里创建了这个帐户.
码:
package secret.package.guys;
import java.util.Scanner;
public class NewClass {
public static void main(String[] args) {
System.out.println("Number: ");
Scanner scanner = new Scanner(System.in);
String data=scanner.nextLine();
System.out.println(data);
int a = 0;
while(a < 6) {
System.out.println(a);
a ;
}
if (a > 6){
System.out.println("SAFE SPACE");
} else {
System.out.println("Get in the Safe Space");
System.out.println("PERSON has entered the Safe Space. Safe Space closes instantly.");
}
String s = new String("Old marks: ");
String t = new String("5.5");
String u = new String("4");
String v = new String("3");
String w = new String("2.5");
String x = new String("6.0");
String y = new String("5.2");
String z = new String("4");
String t1 = t.replaceAll("5.5", "6");
String u1 = u.replaceAll("4", "4");
String v1 = v.replaceAll("3", "5");
String w1 = w.replaceAll("2.5", "3");
String x1 = x.replaceAll("6.0", "2");
String y1 = y.replaceAll("5.2", "1.8");
String z1 = z.replaceAll("4", "4.4");
System.out.println("New: " s " " t1 " " u1 " " v1 " " w1 " "
x1 " " y1 " " z1);
System.out.println("Enter new marks: ");
int foo = Integer.parseInt("t1");
int foo1 = Integer.parseInt("u1");
int foo2 = Integer.parseInt("v1");
int foo3 = Integer.parseInt("w1");
int foo4 = Integer.parseInt("x1");
int foo5 = Integer.parseInt("y1");
int foo6 = Integer.parseInt("z1");
System.out.println("foo1 foo2 foo3 foo4 foo5 foo6");
}
}
解决方法:
您必须在String变量的值上调用parseInt,而不是在变量名称上调用.
例如,
int foo = Integer.parseInt("t1");
应该
int foo = Integer.parseInt(t1);
这只有在t1包含整数的String表示时才会起作用(这意味着parseInt(z1)和parseInt(y1)仍会失败,因为这些字符串不包含整数).来源:https://www.icode9.com/content-1-405001.html