你这个算什么函数啊,看着一头雾水
if语句判断: x<0的时候 y=-1 2x,x=0时 y=-1,x>0时,y=-1 3x
不过另外提一句,你这个y=-1 2x中间是不是少了啥。。。。
import java.io.*;
public class scan {
public static void main(String[] args) throws IOException {
int x,y;
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
if(x<0)
y=2*x-1;
else if(x>0)
y = 3*x-1;
else
y=-1;
System.out.println(y);
}
}
参考代码如下:如有帮助,请采纳一下,谢谢。
int x = 0;
int y = 0;
//输入x
x=SimpleInput.readInt();//读取一个整数
if(x<0)
y = -1 + 2*x;
else if(x == 0)
y = -1;
else
y = -1 + 3*x;
System.out.printf("y=%d\n",y);