-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (40 loc) · 1.23 KB
/
Copy pathMain.java
File metadata and controls
47 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.company;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
// write your code here
printString("feedthedog");
}
private static String printString(String s){
if (s == null || s.length() <= 1) return s;
int len = s.length();
int row = (int) Math.sqrt(len);
int col =(int) Math.round((double)len/(double)row);
if (row * col < len){
col += 1;
}
ArrayList<Character> res = new ArrayList<>();
for (int i = 0;i < col; i ++){
for (int j = 0; j < row; j ++){
if ((col) * j + i < len){
res.add(s.charAt((col)*j + i));
if (j == row - 1){
res.add(' ');
}
}
else{
res.add(' ');
break;
}
}
}
for (int i = 0; i < res.size(); i ++){
System.out.print(res.get(i));
}
System.out.println(len);
System.out.println(row);
System.out.println(col);
//return s;
return res.toString();
}
}