java 如何使用圆轴承

fcipmucu  于 2022-11-20  发布在  Java
关注(0)|答案(1)|浏览(92)

如何将值Map到一组数字(如方位角):例如从0到7方向0 - 1 = 7
Like this

s5a0g9ez

s5a0g9ez1#

根据图片。你的数字从0到7,然后再从0开始;所以我们有min = 0,max = 7。

public static void main(String[] args) throws IOException
       {
           mapNumber(0,7,25); // will print 1
           mapNumber(0,7,31);// will print 7
           mapNumber(0,7,20); // will print 4
           mapNumber(0,7,9); // will print 1
       }
      public static void mapNumber(int start,int end,int noToMap)
      {
       int min = start;
       int max = end;
       int testNumber = noToMap;
       int base = (max - min)+1;
       int mappedNumber =  testNumber % base;
       System.out.println(mappedNumber);
       
}
      
}

相关问题