2016-11-19 45 views
-1

//コードのアイデアはポイントが長方形である場合。入力は6桁の数字(abcdef)です。四角形の左上隅の座標(a、b)は、右下の(C、D)とのポイントがあるの(e、f)はjava、else "エラー:不正な式の開始"の場合

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は、静的またはrun()方法非静的作る、静的メソッドで非静的'Scanner sc'を参照することはできません。

+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

ごめんなさい):)ここで最も役立つ回答を選択し、この質問を回答してください。 –

関連する問題