java获取整数的各位数值
2024-08-29 08:37:28
第一种是取模运算
int qian =input/1000; //千位除以1000
int bai = input/100%10;//百位除以100%10
int shi = input%100/10;//十位%100/10
int ge = input%10;//个位直接%10
System.out.println("千位数"+qian+"百位是"+bai+"十位是"+shi+"个位数是"+ge);
第二种是使用char数组进行分割开依次存到数组
//实现数据 的排序 获取各个位数
public static void main(String[] args) {
System.out.println("请输入一个四位数");
//定义变量接受
@SuppressWarnings("resource")
int number = new Scanner(System.in).nextInt();
if(number>999&&number<10000) {
char[] chars = String.valueOf(number).toCharArray();
System.out.println("千位"+chars[0]);
System.out.println("百位"+chars[1]);
System.out.println("十位"+chars[2]);
System.out.println("个位"+chars[3]);
}else {
System.out.println("你输入的不是四位数··系统终止!!请重新输入!!");
}
}
end
最新文章
- abrt-hook-ccpp: Saved core dump of pid 12224导致dn挂掉问题
- 绘制图形与3D增强技巧(二)----直线图元
- struts2 ,web.xml中配置为/*.action,运行报错Invalid <;url-pattern>; /*.action in filter mapp
- collections——高性能容器数据类型
- div添加透明边框透明背景css
- linux中的strings命令简介2
- docker 指定容器名字
- HDU 3397 Sequence operation(线段树)
- 捣鼓一个Ajax请求管理器
- python编码错误
- 2017广东工业大学程序设计竞赛决赛-tmk买礼物
- 庖丁解牛Linux内核学习笔记(1)--计算机是如何工作的
- Windows 安装 Scoop
- tomcat报异常Invalid character found in method name. HTTP method names must be tokens
- 学习笔记CB011:lucene搜索引擎库、IKAnalyzer中文切词工具、检索服务、查询索引、导流、word2vec
- Deepin 15.5上安装 Node.js
- [PGM] What is Probabalistic Graphical Models
- MySQL Processlist--常见线程状态
- greasemonkey修改网页url
- TCP协议具体解释(上)
热门文章
- Git-GIt检出
- JavaScript 计时事件-setInterval()-clearInterval() -setTimeout()-clearTimeout()
- git上传自己的代码
- error LNK2001: unresolved external symbol __imp___time64
- vim中插入递增数
- Goole Search Auto Complete
- ubuntu16.04中docker安装curl拒绝连接问题
- 动态规划--找零钱 coin change
- Behavior trees for AI: How they work
- vmware安装centos7 安装redis windows7访问redis