我不明白如何修复语法错误

时间:2015-12-10 20:57:02

标签: java syntax error-handling syntax-error

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

    }
  }
}

2 个答案:

答案 0 :(得分:1)

您的代码有一些语法错误......

我修改并注释为评论什么和为什么

...
{       // this is not nescesary
        while ( passed  + failed  < N) { // the hole condition mut be between ()
        if (grades < 6) { //same in the if condition
            failed = failed + 1;
        } //need to close the breakets
        else {
         passed = passed + 1;
        }
        System.out.println(passedperc = F/30*100);
        System.out.println(failedperc = P/30*100);  println is a method, so the parameters mus be enclosed in ()
}   // this is not nescesary

答案 1 :(得分:0)

您的语法完全不正确。

这是一个好的开始,虽然传递,但是失败的,永远不会声明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

    }
}