Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何纠正;“表达式开头非法”;Java中的其他错误?_Java_If Statement - Fatal编程技术网

如何纠正;“表达式开头非法”;Java中的其他错误?

如何纠正;“表达式开头非法”;Java中的其他错误?,java,if-statement,Java,If Statement,我不知道如何纠正这些错误。这是我的代码: import java.io.BufferedReader; import java.io.InputStreamReader; public class Ld1151rdb331 { public static void main(String[] args) { BufferedReader br = new BufferedReader( new InputStreamReader(System.i

我不知道如何纠正这些错误。这是我的代码:

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Ld1151rdb331 {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        float x=0, y=0;
        String s;

        System.out.println("Paula Plauča IRDBD01 151RDB331");

        try {
            System.out.print("x=");
            s = br.readLine();
            x = Float.parseFloat(s);
            System.out.print("y=");
            s = br.readLine();
            y = Float.parseFloat(s);
        } catch(Exception e){
            System.out.println("input-output error");
            return;
        }

        if ((x-4)*(x-4)+(y-3)*(y-3)<=1) || (x-8)*(x-8)+(y-3)*(y-3)<=1) || (y>=5) && ((x-7.5)*(x-7.5)+(y-5)*(y-5)<=(2.5*2.5))
            System.out.println("green");
          else
            if (y>=5 && x>=2 && y<=9-x)
                     System.out.println("blue");
            else
                     if ((x>=2 && x<=5 || x>=2 && x<=10) && y>=3 && y<=7)
                    System.out.println("red");
                else
                    System.out.println("white");
    }
}
导入java.io.BufferedReader;
导入java.io.InputStreamReader;
公共类Ld1151rdb331{
公共静态void main(字符串[]args){
BufferedReader br=新的BufferedReader(
新的InputStreamReader(System.in));
浮动x=0,y=0;
字符串s;
系统输出打印号(“Paula Plauča IRDBD01 151RDB331”);
试一试{
系统输出打印(“x=”);
s=br.readLine();
x=浮点。解析浮点;
系统输出打印(“y=”);
s=br.readLine();
y=浮点。解析浮点;
}捕获(例外e){
System.out.println(“输入输出错误”);
回来
}

如果((x-4)*(x-4)+(y-3)*(y-3)=2&&y=2&&x=2&&x=3&&y则
if
语句中的括号数错误。解决此问题的一种方法是确保用括号括住每个逻辑条件:

if (((x-4)*(x-4)+(y-3)*(y-3)<=1) || 
    ((x-8)*(x-8)+(y-3)*(y-3)<=1) || 
    ((y>=5) && ((x-7.5)*(x-7.5)+(y-5)*(y-5)<=(2.5*2.5))))

if((x-4)*(x-4)+(y-3)*(y-3)您的if语句缺少左括号或右括号,或者格式不正确。这可以为您提供一个良好的开端,而且我建议您使用IDE以避免此类错误

 import java.io.BufferedReader;
 import java.io.InputStreamReader;

 public class Ld1151rdb331 {
 public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    float x = 0, y = 0;
    String s;

    System.out.println("Paula Plau?a IRDBD01 151RDB331");

    try {
        System.out.print("x=");
        s = br.readLine();
        x = Float.parseFloat(s);
        System.out.print("y=");
        s = br.readLine();
        y = Float.parseFloat(s);
    } catch (Exception e) {
        System.out.println("input-output error");
        return;
    }

    if (((x - 4) * (x - 4) + (y - 3) * (y - 3) <= 1)
            || ((x - 8) * (x - 8) + (y - 3) * (y - 3) <= 1)
            || ((y >= 5) && ((x - 7.5) * (x - 7.5) + (y - 5) * (y - 5) <= (2.5 * 2.5))))
        System.out.println("green");
    else if (y >= 5 && x >= 2 && y <= 9 - x)
        System.out.println("blue");
    else if ((x >= 2 && x <= 5 || x >= 2 && x <= 10) && y >= 3 && y <= 7)
        System.out.println("red");
    else
        System.out.println("white");
  }
}
导入java.io.BufferedReader;
导入java.io.InputStreamReader;
公共类Ld1151rdb331{
公共静态void main(字符串[]args){
BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in));
浮动x=0,y=0;
字符串s;
系统输出打印号(“Paula Plau?a IRDBD01 151RDB331”);
试一试{
系统输出打印(“x=”);
s=br.readLine();
x=浮点。解析浮点;
系统输出打印(“y=”);
s=br.readLine();
y=浮点。解析浮点;
}捕获(例外e){
System.out.println(“输入输出错误”);
回来
}

如果((x-4)*(x-4)+(y-3)*(y-3)=2&&y=2&&x=2&&x=3&&y请确保打开括号的数量与关闭括号的数量相匹配。您应该使用正确的编码样式,这样才能真正工作。您所拥有的是不可行的。谢谢,但我不理解最后一个-否则if@PaulaPlauča计算错误的括号表示Java对块从何处开始的理解d结束。一旦你修好了,其他的一切都会好起来的。
 import java.io.BufferedReader;
 import java.io.InputStreamReader;

 public class Ld1151rdb331 {
 public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    float x = 0, y = 0;
    String s;

    System.out.println("Paula Plau?a IRDBD01 151RDB331");

    try {
        System.out.print("x=");
        s = br.readLine();
        x = Float.parseFloat(s);
        System.out.print("y=");
        s = br.readLine();
        y = Float.parseFloat(s);
    } catch (Exception e) {
        System.out.println("input-output error");
        return;
    }

    if (((x - 4) * (x - 4) + (y - 3) * (y - 3) <= 1)
            || ((x - 8) * (x - 8) + (y - 3) * (y - 3) <= 1)
            || ((y >= 5) && ((x - 7.5) * (x - 7.5) + (y - 5) * (y - 5) <= (2.5 * 2.5))))
        System.out.println("green");
    else if (y >= 5 && x >= 2 && y <= 9 - x)
        System.out.println("blue");
    else if ((x >= 2 && x <= 5 || x >= 2 && x <= 10) && y >= 3 && y <= 7)
        System.out.println("red");
    else
        System.out.println("white");
  }
}