如何将整数转换为字符串?

发布于 2025-01-24 04:05:13 字数 155 浏览 3 评论 0原文

我目前正在输入一个程序,并且很好奇我如何能够将整数输入更改为字母,但这是整数所需的特定次数。

例如,我向用户询问了他们有多少个苹果,然后他们输入了三个苹果,然后我将如何将“ 3”变成“ AAA”,或者如果他们输入11并且输出为“ AAAAAAAAAAAAA”。我希望这不是一个例子。

I'm currently typing up a program and was curious as to how I would be able to change an integer input into a letter but it would be the specific amount of times the integer would be.

As an example lets say I asked the user for how many apples they have and they typed in three, how would I then turn that "3" into "aaa", or like if they entered 11 and the output came as "aaaaaaaaaaa". I hope this isn't too bad of an example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2025-01-31 04:05:13

如果您想编程,则必须自己做这些;

int count = your_number, i = 0;
String letter = your_letter;
String result = "";
while (i < count) {
    result += letter;
    i++;
}
System.out.println(result);

或者您可以使用Java strings.utils.repeat()函数
strings.utils

String stringToRepeat = "xxx"
int count = your_count;
String repeated = StringUtils.repeat(stringToRepeat, count);
System.out.println(repeated);

If you want to program, you'll have to do those yourself;

int count = your_number, i = 0;
String letter = your_letter;
String result = "";
while (i < count) {
    result += letter;
    i++;
}
System.out.println(result);

Or you can use Java Strings.Utils.repeat() function
Strings.Utils

String stringToRepeat = "xxx"
int count = your_count;
String repeated = StringUtils.repeat(stringToRepeat, count);
System.out.println(repeated);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文