3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 )
package apple; import java.util.*; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); int x=input.nextInt(); int y; if(x>0) { y=x+3; } else { if (x<0) { y=(2*x)-1; } else y=0; } System.out.println(y); }
}
3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 )