switch(x < 0 ? 1 : x <= 10 ? 2 : 3){
case 1:System.out.println ("x < 0");break;
case 2:System.out.println ("x<=10");break;
case 3:System.out.println ("x>10");
 }

解决方案 »

  1.   

    switch(x < 0 ? 1 : x <= 10 ? 2 : 3){
    case 1:System.out.println ("x < 0");break;
    case 2:System.out.println ("x<=10");break;
    case 3:System.out.println ("x>10");
     }
    ok
      

  2.   

    switch(x < 0 ? 1 : x <= 10 ? 2 : 3){
            case 1: y = 2*x+1;   break;
            case 2: y = x;       break;
            case 3: y = 3*x-5;
    }
      

  3.   

    import java.io.*;
    public class Test{
    public static void main(String[] args)throws IOException{
    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
    int i=0;
    int y=0;
    int t=Integer.parseInt(b.readLine());
    if(i<=0){
    i=0;
    }
    else{
    if(i<=10){
    i=1;
    }
    else{
    i=2;
    }
    }
    switch(i){
    case 0:y=2*t+1;break;
    case 1:y=t;break;
    case 2:y=3*t-5;break;
    }
    System.out.println("y="+y);
    }
    }
      

  4.   

    楼上的兄弟判断时if应该判断变量 t 吧,呵呵,不过程序本身的思路是对的。
      

  5.   

    BufferedReader b=new BufferedReader(new InputStreamReader(System.in));楼上的大哥,我对这有句有问题是啥意思呢?
      

  6.   

    那位兄弟再帮我看看还可以要switch来实现的!
    谢谢~~~