java 五位数前面补0_Java Android 开发数字不足位数前面补0

这里将告诉您Java Android 开发数字不足位数前面补0,具体操作方法:import java.text.DecimalFormat;

public void changeColor(View view) {

DecimalFormat decimalFormat = new DecimalFormat("000");

//获取随机数对象,产生三个随机数值(RGB值)

Random x = new Random();

int red = x.nextInt(256);

String sred = decimalFormat.format(red);

txvR.setText("红:"+sred);

txvR.setTextColor(Color.rgb(red,0,0));

int green = x.nextInt(256);

String sgreen = decimalFormat.format(green);

txvG.setText("绿:"+sgreen);

txvG.setTextColor(Color.rgb(0,green,0));

int blue = x.nextInt(256);

String sblue = decimalFormat.format(blue);

txvB.setText("蓝:"+sblue);

txvB.setTextColor(Color.rgb(0,0,blue));

//设置界面最上方的按钮 button 的文字颜色

button.setTextColor(Color.rgb(red,green,blue));

//设置界面最下方的空白 LinearLayout 的背景颜色

colorBlock.setBackgroundColor(Color.rgb(red,green,blue));

}

import java.text.DecimalFormat;

//如果数字1是字符串,如下处理:

String string="1";

DecimalFormat decimalFormat =new DecimalFormat("0000");

String string2=decimalFormat.format(Integer.parseInt(str1));

System.out.println(string2);

//如果数字1是整型,如下处理:

int string=1;

DecimalFormat decimalFormat =new DecimalFormat("0000");

String string2=decimalFormat.format(string);

System.out.println(string2);

Java Android 开发数字不足位数前面补0就为您介绍到这里,感谢您关注懒咪学编程c.lanmit.com.

本文地址:https://c.lanmit.com/bianchengkaifa/Java/16930.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值