代码:
import java.util.*; public class Test { public static void main(String[] args) { int x,y; Scanner rd=new Scanner(System.in); System.out.println("请输入x的值:"); x=rd.nextInt(); if(x<0) y=-x; else if(x>=0&&x<8) y=2*x+1; else y=4*x; System.out.println("y="+y); } }