基本程序,但解决方案是什么?

时间:2016-11-05 11:05:04

标签: java

主档案:

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指获得的标记

1 个答案:

答案 0 :(得分:0)

您无法使用omarks外部构造函数或方法

public void percentage() {
    omarks = c1 + c2 + c3 + c4 + c5;
    double p = (omarks/tmarks) * 100;
    System.out.println("Percentage: " + p);
}