MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / encryption

Method encryption

Hackerank/Java/Encryption.java:12–40  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

10
11 // Complete the encryption function below.
12 static String encryption(String s) {
13 String s2 = "";
14 for (int i = 1; i <= s.length() ; i++){
15 String temp = s.substring(i-1,i);
16 if(!temp.equals(" ")){
17 s2 = s2 + temp;
18 }
19 }
20 double a = Math.sqrt(s2.length());
21 int b = (int)a+1;
22 if(a%1 == 0){
23 b = (int)a;
24 }
25 if (a*b < s2.length()){
26 a++;
27 }
28
29 String ans = "";
30 for (int i = 0 ; i < b ; i++){
31 for (int j = i ; j < s2.length();j+=b){
32 ans = ans + s2.substring(j,j+1);
33 }
34 ans = ans + " ";
35 }
36
37
38
39 return ans;
40 }
41
42 private static final Scanner scanner = new Scanner(System.in);
43

Callers 1

mainMethod · 0.95

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected