Answer the question
In order to leave comments, you need to log in
How to duplicate letters in a string?
For example, when typing the word
Important
from the keyboard, the word Important should display duplicated words as shown below
:
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
int sizeOfInput = input.length();
for (int i = 0; i < sizeOfInput; i++) {
int endIndex = i+1;
String dup = input.substring(i, endIndex);
System.out.print(dup + dup + dup);
}
Answer the question
In order to leave comments, you need to log in
var multiplied = Arrays.stream("Important".split(""))
.flatMap(s -> Stream.of(s, s, s))
.collect(Collectors.joining());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question