我的 Java 程序出现以下错误:
Java 变量未初始化错误...错误:变量 nam 和 r 未初始化位置类子项
但是已经初始化了nan
,r
但我仍然遇到同样的错误。
public class cla {
int rn;
String name;
void get(String a, int x) {
name = a;
rn = x;
}
void display() {
System.out.println("student name: " + name + "roll no.:" + rn);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class child {
public static void main(String args[]) throws IOException {
String nam;
int r;
BufferedReader bReader = new BufferedReader(new InputStreamReader(
System.in));
try {
System.out.println("enter name and roll no.");
nam = bReader.readLine();
r = Integer.parseInt(bReader.readLine());
} catch (Exception e) {
}
cla c = new cla();
c.get(nam, r);
c.display();
}