gpt4 book ai didi

java - 我不明白如何解决语法错误

转载 作者:行者123 更新时间:2023-12-03 09:06:35 25 4
gpt4 key购买 nike

public static void main(String[] args){
int passed = 0;
int failed = 0;
int N;
int grades;
{
while ( passed + failed ) < N {

if grades < 6 {
failed = failed + 1;
else
passed = passed + 1;

system.out.println passedperc = F/30*100
system.out.println failedperc = P/30*100

}
}
}

最佳答案

您的语法完全不正确。

这是一个不错的开始,尽管甚至不会声明passper,failedperc,F和P。此外,没有正确遵循变量约定。

public class TestClass {

public static void main(String[] args) {
int passed = 0;
int failed = 0;
int n = 0; //don't leave uninitialized and uncaptialize
int grades = 0; //same here

while ((passed + failed) < n) { //parens not correct

if (grades < 6) {//same here and missing brackets
failed = failed + 1; //can be changed to failed += 1;
} else
passed = passed + 1; //also can be changed using +=

}
//System print statements are wrong and variables are never declared or initialized
System.out.println(passedPerc = f / 30 * 100);//use camelCase don't use capital variables unless they are constants
System.out.println(failedPerc = p / 30 * 100);//same here

}
}

关于java - 我不明白如何解决语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34211591/

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