0

次の if 条件で true と評価された式を見つけることは可能ですか。それに基づいて a の値を見つけることができます。

import java.util.*;


 class a {





    public static void main(String args[]){

        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int i=0;i<100;i++){
            if((i==a)||((i+100)==a)||((i+200)==a)||((i+300)==a)||((i+400)==a)||((i+500)==a)||((i+600)==a)||((i+700)==a)||((i+800)==a)||((i+900)==a)){
                //code 
                System.out.println("? condition is evaluated true");
            }

        }
     }
}
//I don't want to take more than one if statement.
4

2 に答える 2

9

この特定のケースでは、式 (ai)/100 は、真であった条件のインデックスを示します。

于 2013-10-07T12:43:05.433 に答える
0

別の for ループを使用することをお勧めします。

public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    for (int i=0; i<100; i++)
        for (int j=0; j<1000; j+=100)
            if (i + j == a)
                System.out.println(Integer.toString(j / 100) + " condition is evaluated true");
}
于 2013-10-07T12:46:52.517 に答える