m=y-x;
System.out.println("最大数与最小数之差为"+m);
}else
{
System.out.println("最小数为"+y);
System.out.println("最大数为"+x);
m=x-y;
System.out.println("最大数与最小数之差为"+m);
}
}
}
9、编写程序,计算下列分段函数的值。
x? (x>0)
y=???? 0? (x=0)
-x? (x<0)
import java.io.*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x,y;
y=0;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println("请输入x:");
String temp=input.readLine();
x = Float.parseFloat(temp);
if(x>0)
{
y=x;
}
if(x==0)
{
y=0;
}
if(x<0)
{
y=-x;
}
System.out.println("y="+y);
}
}
10、编写程序,计算下列分段函数的值。
x-1? (x>1)
y=???? 0? (-1≤x≤1)
x+10? (x<-1)
import java.io.*;
public class testa
{
public static void main(String[] args) throws IOException
{
float? x,y;
y=0;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println("请输入x:");
String temp=input.readLine();
x = Float.parseFloat(temp);
if(x>1)
{
y=x-1;
}
if(1.0>=x&&x>=-1.0)
{
y=0;
}
if(x<-1)
{
y=x+10;
}
System.out.println("y="+y);
}
}