运行结果:
代码如下:
import java.util.Scanner;
public class App65 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入x值:");
int x = scanner.nextInt();
int y = 0;
if (x < 0) {
y = x * x;
} else if (x >= 0 && x < 10) {
y = 2 * x - 1;
} else if (x >= 10) {
y = 3 * x - 11;
}
System.out.println("y=" + y);
}
}