0

Is it possible to find which expression evaluated true in the following if condition and on that basis I can find the value of 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 回答