三目运算出错 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; ------解决方案--------------------
在比较一次呗 ------解决方案--------------------
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);