import java.util.Scanner;
public class C {
public static void main(String[] args) {
int x;
int y=0;
System.out.println("请输入X的值");
Scanner q = new Scanner(System.in);
x = q.nextInt();
if (x > 0)
{
y= x + 2;
}
else if (x == 0)
{
y= x - 2;
}
else if (x < 0)
{
y= x - 4;
}
System.out.println("y="+y);
}
}
public static void main(String[] args) {
try{
Scanner sc = new Scanner(System.in);
System.out.print("请输入X的值: ");
int x = sc.nextInt();
int value = getY(x);
System.out.println("y = " + value);
}catch(Exception e){
System.out.println("请输入数字");
}
}
private static int getY(int x) {
int value = 0;
if(x > 0){
value = x + 2;
}else if(x < 0){
value = x - 4;
}else{
value = x - 2;
}
return value;
}
Scanner sc=new Scanner(System.in);
System.out.println("请输入x的值");
int x=sc.nextInt();
int y=0;
if(x>0){
y=x+2;
}else if(x==0){
y=x-2;
}else{
y=x-4;
}
System.out.println(y);
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Test t = new Test();
t.test();
}
public void test() {
System.out.println("请出入x的值:");
Scanner input = new Scanner(System.in);
int x = input.nextInt();
if (x > 0) {
x += 2;
} else if (x == 0) {
x -= 2;
} else {
x -= 4;
}
int y = x;
System.out.println(y);
}
}
if(x>0) Y=x+2;
else if(x<0) Y=x-4;
else Y=x-2; // x=0
System.our.println("Y="+Y);
public int getY(int x)
{
if (x > 0)
{
return x + 2;
}
else if (x == 0)
{
return x - 2;
}
else if (x < 0)
{
return x - 4;
}
return 0;
}