You are viewing a single comment's thread. Return to all comments →
I haven't use 2d array in my solution
static String encryption(String s) {
char arr[] = s.toCharArray(); String ans = new String(); int length = 0; if(Math.sqrt(arr.length) % 1 == 0){ length = (int)(Math.sqrt(arr.length)); }else{ length = (int)(Math.sqrt(arr.length)+1); } System.out.println(arr.length+" "+length); for(int i = 0; i < length ; i++) { for(int j=i; j < arr.length ; j++){ if(j < arr.length){ ans+=arr[j]; j+=(length-1); } } if(i != length){ ans += ' '; } } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
I haven't use 2d array in my solution
static String encryption(String s) {