日期:2014-05-20  浏览次数:20745 次

三目运算出错
import java.io.*;
public class T
{
 public static void main(String[] args) throws IOException
 {
   int x,y,z,min;
   InputStreamReader reader=new InputStreamReader (System.in);
   BufferedReader input=new BufferedReader (reader);
   System.out.println("请输入三个数!");
   x=Integer.parseint(input.readLine());
   y=Integer.parseint(input.readLine());
   z=Integer.parseint(input.readLine());
   x<y?min=x:min=y;
   min<z?min:min=z;
   System.out.println("这三个数中最小的数是:"+min);  
  }
}
这里  x<y?min=x:min=y;
      min<z?min:min=z;
这样敲不对吗?
java

------解决方案--------------------
要被赋值的变量  = (表达式) ? 结果1 : 结果2
------解决方案--------------------
min=x<y?x:y;
------解决方案--------------------
public class tt
{
 public static void main(String[] args) throws IOException
 {
   int x,y,z,min;
   InputStreamReader reader=new InputStreamReader (System.in);
   BufferedReader input=new BufferedReader (reader);
   System.out.println("请输入三个数!");
   x=Integer.parseInt(input.readLine());
   y=Integer.parseInt(input.readLine());
   z=Integer.parseInt(input.readLine());
   min = x<y?x:y;
   min = min<z?min:z;
   System.out.println("这三个数中最小的数是:"+min);  
  }
}这样
------解决方案--------------------
min = x<y?min=x:min=y;
min = min<z?min:min=z;
------解决方案--------------------
引用:
好的,感谢上面的解答,昨天弄完了求最大最小的,今天又发现了个三目的问题,现在不是要求最大最小,而是要求三个数从小到大排序,也是用上面的方法,要求把最大的赋值给a,最小的赋值给c,中间的赋值给b,最大最小的我会比较,但是中间的我就想不出来,该怎么比较然后赋值给中间数b?

在比较一次呗
------解决方案--------------------
import java.io.*;
public class T
{
 public static void main(String[] args) throws IOException
 {
   int x,y,z,min;
   InputStreamReader reader=new InputStreamReader (System.in);
   BufferedReader input=new BufferedReader (reader);
   System.out.println("请输入三个数!");
   x=Integer.parseint(input.readLine());
   y=Integer.parseint(input.readLine());
   z=Integer.parseint(input.readLine());
   x<y?min=x:min=y;
   min<z?min:min=z;
   System.out.println("这三个数中最小的数是:"+min);  
  }
}

------解决方案--------------------
import java.io.*;

public class T {
public static void main(String[] args) throws IOException {
int x, y, z, min;
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);