Java Basics Part Two -16 Problems with Solutions
Problem-1 Given a string and a non-negative int n, return a larger string that is n copies of the original string. Example: stringTimes(“Hi”, 2) → “HiHi” stringTimes(“Hi”, 3) → “HiHiHi” stringTimes(“Hi”, 1) → “Hi” Solution public String stringTimes(String str, int n) { String y=””; // empty string to store the result for (int i=0;i<n; i++){ … [Read more…]