gpt4 book ai didi

java - 如何解决线程 "main"java.lang.NullPointerException 错误中的异常

转载 作者:搜寻专家 更新时间:2023-11-01 00:59:44 25 4
gpt4 key购买 nike

<分区>

我在 Java 程序中遇到问题。线程“main”中的异常

java.lang.NullPointerException
at twoten.TwoTenB.<init>(TwoTenB.java:29)
at javapractice.JavaPractice.main(JavaPractice.java:32)
Java Result: 1

是我遇到的错误。我真的需要一些帮助,因为我在这个地方被困了几个小时......

package twoten;

import java.util.Scanner;

public class TwoTenB {

public TwoTenB() {
double percentage;
double a[] = null;
double total = 0;
double var;
System.out.print("\tRESULT\n\n");
Scanner scan = new Scanner(System.in);
//double[] mark = new double[7];
for (int i = 0; i < 7; i++) {

System.out.print("\nMarks in subject " + (i + 1) + "\t:\t");
var = scan.nextDouble();

a[i] = var;

total = total + a[i];
//percentage = first * second * third * fourth * fifth * sixth * seventh * 100 / 700;
}

percentage = total * 100 / 700;

if (a[0] > 35 && a[1] > 35 && a[2] > 35 && a[3] > 35 && a[4] > 35 && a[5] > 35 && a[6] > 35 && percentage > 35) {
if (percentage >= 60) {
System.out.print("\nCongratulation!!! you've got FIRST dividion\n");
} else if (percentage >= 45 && percentage < 60) {
System.out.print("\nCongratulation!!! you've got SECOND dividion\n");
} else if (percentage >= 35 && percentage < 45) {
System.out.print("\nCongratulation!!! you've got THIRD dividion\n");
}
} else {
System.out.print("\nSORRY!!! you've FAILED\n");
}
}
}

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