/*
键盘录入x的值,计算出y的并输出。
x和y的关系满足如下:
x>=3 y = 2x + 1;
-1<=x<1 y = 2x;
x<-1 y = 2x – 1;
*/
import java.util.Scanner;
class IfDemo4{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入x的值:");
int x = sc.nextInt();
int y;
if(x>=3){
y = 2*x+1;
}else if(-1<=x && x<1){
y = 2*x;
}else if(x<-1){
y = 2*x-1;
}else{
System.out.println("x输入的值无效,y自动赋值为0");
y = 0;
}
System.out.println("y="+y);//错误: 可能尚未初始化变量y
}
}