導航:首頁 > 編程語言 > javaformat字元串後補零

javaformat字元串後補零

發布時間:2023-03-20 17:35:56

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的話,要看你需要加幾個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數字自動補零

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中如何將數字轉化為字元串並且不足位數補0

具體操作如下:

String str1="1";

DecimalFormatdf=new DecimalFormat("0000");

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

System.out.println(str2);

JAVA

閱讀全文

與javaformat字元串後補零相關的資料

熱點內容
專題學習網站源碼 瀏覽:163
jsphead什麼 瀏覽:88
gps串口數據怎麼發送 瀏覽:968
win10文件主頁共享查看 瀏覽:411
中國聯通有哪些app是免流的 瀏覽:176
邊做邊保存的文件找不到了 瀏覽:858
win10照片應用文件夾名稱 瀏覽:966
編程如何解決資金的原子性 瀏覽:638
如何製作廣角鏡頭矯正文件 瀏覽:513
在網頁開發中應該選用哪個資料庫 瀏覽:742
iphone5移動卡貼 瀏覽:990
電腦文件的格式 瀏覽:127
extjs的xtype 瀏覽:959
suse11iso文件要u盤安裝 瀏覽:153
如何將報表統計數據轉化為圖形 瀏覽:444
如何寄快遞材料文件 瀏覽:265
java構造方法private 瀏覽:475
手機文件找回恢復 瀏覽:516
word怎麼把u盤里的文件拔掉 瀏覽:976
港版蘋果用的插排 瀏覽:1000

友情鏈接