Myntra Interview Question
Country: India
Interview Type: Written Test
If using recursion is allowed then we can generate as
package com.practice.algo;
public class PrinNNString {
private static void printNNString(String s, int n, int k) {
if (k == 1) {
for (int i = 0; i < n; i++) {
System.out.print(s);
}
} else {
for (int i = 0; i < n; i++) {
printNNString(s, n, k - 1);
}
}
}
private static void printNNString(String s, int n) {
printNNString(s, n, n);
System.out.println("");
}
public static void main(String[] args) {
printNNString("Hello", 3);
printNNString("Hello", 2);
printNNString("Hello", 1);
}
}
Can you give me an example of an output?
- 123ayanjit August 31, 2019