2016-11-19 15 views
-1

//代码的想法如果看到点是在矩形中。输入是一个6位数字(abcdef)。矩形的左上角坐标为(A,B),右下(C,d)和点(E,F)java,否则如果“错误:表达式的非法开始”

enter codeimport java.util.Scanner; 

public class Rectangle{ 
Scanner sc = new Scanner(System.in); 

public static void run() { 
int object; 
System.out.println("input:"); 
object = sc.nextInt(); 

if(object/100000 >= (object/1000)%10 || (object/10000)%10 <= (object/100)%10){ 
    System.out.print("inside"); 
}else if (object/100000 <= (object/10)%10 && (object/10)%10 <= (object/1000)%10 && (object/100)%10) <= object%10 && object%10 <= (object/10000)%10){ 
    System.out.print("inside"); 
}else { 
    System.out.print("outside"); 
} 


    public static void main(String[] args) { 
    (new Rectangle()).run(); 
    } 
} 
+0

在if语句中检查括号... – Ansharja

+0

为什么在主要方法中有一个随机打开的护腕? –

+1

你的'run'方法在'else'块之后缺少一个关闭'}'。 –

回答

0

这是因为你在else if声明在第三个条件额外)

else if (object/100000 <= (object/10)%10 && 
     (object/10)%10 <= (object/1000)%10 && 
     (object/100)%10 remove it--->) <= object%10 && 
      object%10 <= (object/10000)%10){ 

你也不能引用静态方法非静态'Scanner sc',使Scanner sc静态或run()方法非静态的。

+0

非常感谢 –

1

你的括号错了,请用你的代码的格式工具。我发布下面的固定代码。请注意,条件必须包含在()括号内。

if (condition) { ... } 

// In case there are complete calculations within condition 
if ((condition) && (condition) && (condition)) { ... } 

而且它肯定说:

non-static method cannot be referenced from a static context

这个错误应该因为你使用的Scanner实例,这不是静态的,以及去除static关键字是固定的。

Scanner sc = new Scanner(System.in); 

public void run() { 
    int object; 
    System.out.println("input:"); 
    object = sc.nextInt(); 

    if (object/100000 >= (object/1000) % 10 || (object/10000) % 10 <= (object/100) % 10) { 
     System.out.print("inside"); 
    } else if (((object/100000 <= (object/10) % 10) && 
      ((object/10) % 10 <= (object/1000) % 10) && 
      ((object/100) % 10) <= object % 10) && 
      (object % 10 <= (object/10000) % 10)) 
    { 
     System.out.print("inside"); 
    } else { 
     System.out.print("outside"); 
    } 
} 

public static void main(String[] args) { 
    new Rectangle().run(); 
} 
+0

非常感谢你,对于发布错误感到抱歉,我第一次发帖 –

+0

没有什么可抱歉的:))请考虑选择这里最有用的答案作为接受,并提出这个问题amswered。 –