import java.io.StringWriter;
public class ColumnToStringConverter {
public static String convertColumnToString(int[][] matrix, int col) {
int rows = matrix.length;
StringBuilder str = new StringBuilder();
StringWriter sw = new StringWriter();
for (int i = 0; i < rows; i++) {
sw.write(String.valueOf(matrix[i][col]));
str.append(sw.toString()).append(" ");
sw.getBuffer().setLength(0);
}
return str.toString().trim();
}
public static void main(String[] args) {
int[][] matrix = {
{ 4, 7, 9, 18, 29, 0},
{ 1, 9, 18, 99, 4, 3},
{ 9, 17, 89, 2, 7, 5},
{19, 49, 6, 1, 9, 8},
{29, 4, 7, 9, 18, 6}
};
int col = 3;
String str = convertColumnToString(matrix, col);
System.out.println(str);
}
}
/*
run:
18 99 2 1 9
*/