1.

/**
* Author : Felix Dietrich
* Problem : 11716 - Digital Fortress
* Link : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=117&problem=2763&mosmsg=Submission+received+with+ID+7581195
* Method : String Manipulation
* Runtime : 0.172
*/
import java.io.*;

public class Main
{

public static void main(String... sts) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
int testcases;
int sqrtLen;
StringBuffer sb;

testcases = Integer.parseInt(reader.readLine());

for (int i = 0; i < testcases; i++)
{
input = reader.readLine();

sqrtLen = (int) Math.sqrt(input.length());

if (sqrtLen * sqrtLen != input.length())
{
sb = new StringBuffer("INVALID");
}
else
{
sb = new StringBuffer();
for (int k = 0; k < sqrtLen; k++)
{
for (int l = 0; l < sqrtLen; l++)
{
sb.append(input.charAt(l * sqrtLen + k));
}
}
}

System.out.println(sb.toString());
}
}
}

2.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 11716 - Digital Fortress
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2763
*
* @author Dennis Wilfert
* @version 1.0, 11/26/2009
*
* Status : Accepted
* Runtime: 0.156
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder output = new StringBuilder();
char[] line;
int length, j, k, sqrt;

for (int i = Integer.parseInt(reader.readLine()); i > 0; i--) {

line = reader.readLine().toCharArray();

length = line.length;
// Länge pro Zeile/Spalte im Quadrat ausrechnen
sqrt = (int) Math.sqrt(length);

// Im array die richtigen Buchstaben suchen und an die Ausgabe anhängen
if (sqrt * sqrt == length) {
for (j = 0; j < sqrt; j++) {
for (k = 0; k < length; k += sqrt) {
output.append(line[j + k]);
}
}
} else {
output.append("INVALID");
}
output.append("\n");
}
System.out.print(output);
}
}