主档案:
public static void main(String[] args) {
NewClass obj = new NewClass();
Scanner inp = new Scanner(System.in);
System.out.println("Enter marks of 5 subjects: ");
obj.c1 = inp.nextInt();
obj.c2 = inp.nextInt();
obj.c3 = inp.nextInt();
obj.c4 = inp.nextInt();
obj.c5 = inp.nextInt();
obj.percentage();
}
}
班级档案:
public class NewClass {
int tmarks;
int omarks;
int c1, c2, c3, c4, c5;
NewClass () {
this.tmarks = 500;
}
omarks = c1 + c2 + c3 + c4 + c5;
public void percentage() {
double p = (omarks/tmarks) * 100;
System.out.println("Percentage: " + p);
}
}
我在类文件中收到错误"无法找到符号omarks"。问题是什么?
注意: 标记是指总标记 omarks指获得的标记
答案 0 :(得分:0)
您无法使用omarks
外部构造函数或方法
public void percentage() {
omarks = c1 + c2 + c3 + c4 + c5;
double p = (omarks/tmarks) * 100;
System.out.println("Percentage: " + p);
}