题解 | #计算y的值#
计算y的值
http://www.nowcoder.com/practice/61a0f16117484d219b59c62224b33b1c
题解思路
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sin = new Scanner(System.in);
int y = 0;
while(sin.hasNext()){
int x = sin.nextInt();
// x小于0 y就等于1 x等于0,就等于0 因为y本来就等于0所有这个判断不用写
// x 大于0,y就等于-1
if(x < 0){
y = 1;
}else if(x > 0){
y = -1;
}
System.out.println(y);
}
}
}