如何将前导零添加到String
问题描述:
嗨朋友们,
i需要帮助..
i得到字符串值,我需要添加前导零..
目标字符串的总长度是13char
例如:假设我得到12作为值..
它需要转换为0000000000012
假如我得到125.it需要转换为0000000000125
目标字符串应为13char ..
我们需要在源字符串中添加前导零,使结果字符串为13个字符,结果字符串需要重新调整
请帮帮我
Ram
Hi friends,
i need help ..
i am getting String value and i need to add leading zeros..
total length of Target string is 13char
eg: suppose if i get 12 as values..
it needs to convert into 0000000000012
suppose if i get 125 .it needs convert into 0000000000125
target string should be 13char..
we need to add leading zeros to the source string to make result string to 13 char and result string needs to retun
please help me
Ram
答
欢迎来到TSDN。
这个网站不是用来发布开始的代码。
如果您的代码有问题,那么专家会在这里更正您的代码。
soooooo ................
你做了多少?
尝试编写自己的代码。
如果你遇到任何问题就发布该代码。
>
祝您好运。
亲切的问候。
dmjpro。
welcome to TSDN.
this site is not for post the code from begining.
if u have a problem with ur code then the experts r here to correct ur code.
soooooo................
how much u did?
try to write the code ur self.
then post that code if u facing any problem.
best of luck.
kind regards.
dmjpro.
嗨感谢您的回复
i am new java ,,,
i尝试使用此代码...
String addZeros(Sting a)
{
int i = 0;
i = a.length();
if(i = 13)
返回a;
else
{
int j = 13 - i;
for(int k = 0; K< = j的; j ++)
{a =" 0" + a;}
返回a;
}
}
我的系统挂起......
请指导
hi thanks for your reply
i am new java,,,
i tried with this code...
String addZeros(Sting a)
{
int i=0;
i=a.length();
if ( i = 13 )
return a;
else
{
int j= 13 - i;
for (int k=0; k<=j; j++)
{a="0"+a;}
return a;
}
}
my systems getting hanging....
please guide
>
我是java的初学者。
我写的是在领先的空间加0'。尝试并给出你的评论是否满足你的需求。
Hi,
Im beginers for java.
I write to add 0''s in leading space. try it and give ur comments whether it satisfies ur needs or not.
展开 | 选择 | Wrap | 行号