取数位

求1个整数的第k位数字有很多种方法。
以下的方法就是一种。
还有一个答案:f(x/10,k--) public class Main { static int len(int x){ // 返回多少位
if(x<10) return 1;
return len(x/10)+1;
} // 取x的第k位数字
static int f(int x, int k){ //数字 第几位数23513 5-3=2
if(len(x)-k==0) return x%10; //如果是最后一位数
return (int) (x/Math.pow(10, len(x)-k)%10); //填空
} public static void main(String[] args)
{
int x = 295631;
//System.out.println(len(x));
System.out.println(f(x,4));
} }

最新文章

  1. CRLF line terminators导致shell脚本报错:command not found
  2. Windows 7 封装篇(一)【母盘定制】[手动制作]定制合适的系统母盘
  3. JS js与css的动态加载
  4. HTML5新特性及详解
  5. linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write【转】
  6. 三步将Node应用部署到Heroku上 --转载
  7. html5文本框提示文字属性为placeholder
  8. css 关于两栏布局,左边固定,右边自适应
  9. UVA 125 Numbering Paths
  10. python-文件压缩和解压
  11. Session、Application、Cache
  12. MySQL5.7: sql script demo
  13. 什么是java字节码?
  14. Titanic缺失数值处理 &amp; 存活率预测
  15. leetcode33
  16. react native 使用TabNavigator编写APP底部导航
  17. Docker的常用命令
  18. ES6之Promise对象
  19. Swift 错误记录
  20. Faster R-CNN在GPU下的安装、测试经历

热门文章

  1. STM32编程:是时候深入理解栈了
  2. jquery监听input
  3. python 调用ldap同步密码
  4. SpringBoot +Vue 前后端分离实例
  5. 百度编辑器ueditor异步载入的操作方法
  6. HDU-6393 Traffic Network in Numazu
  7. HDU5293 树链剖分+树形DP
  8. Visual Studio 2019 Professional 激活
  9. 【转】Mac系统常用快捷键大全
  10. 性能测试之服务器监控和Prometheus推荐