Switch case for two INT variables

前端 未结 6 1400
生来不讨喜
生来不讨喜 2021-01-12 19:07

Consider the following code :

if (xPoint > 0 && yPoint > 0) {
    m_navigations = Directions.SouthEast;
}
else if (xPoint > 0 && yP         


        
6条回答
  •  猫巷女王i
    2021-01-12 19:44

    Use signum to get -1, 0 or 1 on the direction like this:

    String direction = Integer.signum(xPoint)+","+Integer.signum(yPoint);
    switch(direction){
      case "1,1": 
        m_navigations = Directions.SouthEast;
        break;
      case "-1,0"
        m_navigations = Directions.West;
        break;
    
    etc..
    }
    

提交回复
热议问题