Advertisement
STANAANDREY

accum

Jul 22nd, 2021
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. package com.company;
  2. import java.lang.*;
  3. import java.util.Locale;
  4.  
  5. class Accumul {
  6.  
  7.     public static String accum(String s) {
  8.         // your code
  9.         var strb = new StringBuilder("");
  10.         for (int i = 0; i < s.length(); i++) {
  11.             String toBeAdded = String.valueOf(s.charAt(i));
  12.             strb.append(toBeAdded.toUpperCase(Locale.ROOT));
  13.             for (int aux = i; aux > 0; aux--) {
  14.                 strb.append(toBeAdded);
  15.             }
  16.             strb.append("-");
  17.         }
  18.         strb.setLength(Math.max(strb.length() - 1, 0));
  19.         return strb.toString();
  20.     }
  21. }
  22.  
  23. public class Main {
  24.  
  25.     public static void main(String[] args) {
  26.         System.out.println(Accumul.accum("abcd"));
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement