導航:首頁 > 編程語言 > javaint補零

javaint補零

發布時間:2021-02-21 20:32:17

『壹』 java一個數字的位數不夠怎麼在前面加0

import java.text.DecimalFormat;
//(1)、如果數字1是字元串,如下回處理:
String str1="1";
DecimalFormat df=new DecimalFormat("0000");
String str2=df.format(Integer.parseInt(str1));
System.out.println(str2);
//(2)、如果數字1是整答型,如下處理:
int str1=1;
DecimalFormat df=new DecimalFormat("0000");
String str2=df.format(str1);
System.out.println(str2);

『貳』 java數字自動補零

public class P {
public static void main(String[] args){
String pattern="000";
java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
int i = 10,j=6;
System.out.println("i="+df.format(i)+"\nj="+df.format(j));
}
}
---------------------輸出-----------------------
i=010
j=006

『叄』 java 如何補零

這樣是一個例子

『肆』 java一個數字的位數不夠怎麼在前面加0

具體操作如下:

String str1="1";

DecimalFormat df=new DecimalFormat("0000");

String str2=df.format(Integer.parseInt(str1));

System.out.println(str2);

『伍』 java中如何將數字轉化為字元串並且不足位數補0

具體操作如下:

String str1="1";

DecimalFormatdf=new DecimalFormat("0000");

String str2=df.format(Integer.parseInt(str1));

System.out.println(str2);

JAVA

『陸』 java 右補零問題

用java.text包中的DecimalFormat方法

例子如下:版

import java.text.*;

class Main
{
public static void main(String[] args)
{
double d=1.23;
DecimalFormat g=new DecimalFormat("0.000000");
System.out.println(g.format(d));
}
}

運行結果權 1.230000

『柒』 JAVA 日期 INT變數小於10時,怎麼給它補0,求解

給你個例子吧

import java.text.*;
import java.util.*;

public class GetTime {
public static void main(String[] args) {
MyThread mt = new MyThread();
mt.start();
}
}

class MyThread extends Thread {

public void run() {
while(true) {
Date d=new Date();//獲取時間
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd kk:mm:ss ");//轉換回格式
System.out.println(sdf.format(d));//列印答

try {
Thread.sleep(1000);
} catch(InterruptedException e) {
e.printStackTrace();
}
}

}
}

『捌』 java 怎樣將整數轉換成字元串時,前面加零

首先字抄符串前面襲加0的話,要看你需要加幾個0,java的String類有個format方法可以在字元串的前面加0。形如:String.format("%07d", "str");表示整數長度為7,如果不到7位就用0填充。
比如:String str = "hello";如果你想在hello前面加0的話,就str = String.format("%07d", str);這里的意思表示,如果str不夠7位,就用0補充,得到的結果是str = "00hello";
希望能幫到你。

『玖』 java的字元型數組補零

import java.util.Scanner;

public class T
{
public static void main(String[] args)
{
int n;
System.out.print("請輸入數組a的長專度屬:");
Scanner sc = new Scanner(System.in);
n=sc.nextInt();

char[] a = new char[n];
char[] b = new char[200];
for(int i=0;i<n;i++)
a[i]='1';
for (int i = 0; i < 200; i++)
b[i]='0';
for(int j=0;j<n;j++)
b[199-j]=a[j];
System.out.println(b);
}
}

『拾』 java 一個數字的位數不夠怎麼在前面加0

inti=1;
Strings=String.format("%02d",i);
System.out.println(s);//print01

閱讀全文

與javaint補零相關的資料

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接