0

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.

LastCheck
  • 9
  • 3

1 Answers1

0

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);
Charlo Poitras
  • 198
  • 1
  • 14