Had to delete some parts of the solution so i can post here.
Question is solved after just 27 tries but still have some questions = 🤡
1🤡 what is with String result, whats the purpose if anyway result *= s.
2🤡 why first i = 1 and second i = 0 ? it gives same 5 outputs with first and second i (both) = 1. just wont pass the requirements if they r same "1". any thoughts ?
thaaank youu
public class StringHelper {
public static String multiply(String s) {
🤡String result = "";
🤡 for (int i = 1; i <= 5; i++){
public static String multiply(String s, int count) {
String result = "";
🤡for (int i = 0; i < count; i++){
public static void main(String[] args) {
String s = "Amigo";
System.out.print(multiply(s));
p.s.
I got my sixth promotion this week, and I still don't know what I do!
WhyResult
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
13 August 2021, 15:06solution
It needs to loop a certain amount of times:
(i = 1; i <= 5; i++)
this read i starts at 1; the loop continues as long as i is less than OR equal to 5; then i is increased each loop cycle. This results in i being 1, 2, 3, 4, 5 for 5 loop cycles
(i = 1; i < 5; i++)
this read i starts at 1; the loop continues as long as i is less than 5; then i is increased each loop cycle. Notice the difference between the top one and this one: the first one is "<=" while this one is just "<". The result is i will be 1, 2, 3, 4 and only loop 4 times. This is 1 less than the required amount.
The standard way is to start at 0 and not 1, and use the less than "<" operator rather than the less than or equal to "<=". So:
(i = 0; i < 5; i++)
now i will be 0, 1, 2, 3, 4 for a total of 5 loops. This is best practice because Array indices start at 0 and with this loop structure you can access each index with i.
+2
jerry
13 August 2021, 16:43
Thank you
its clear for now ahah
i = 1; i < 5 does not include 0 and requirements r 5
0