I have no idea why this is giving me an error. I tried to run on GDBonline
Question:
I have no idea why this is giving me an error. I tried to run on GDBonline but class gave me an error. Even in Eclipse IDE had giving me the same error.
import java.io.File;
import java.io.IOException;
import java.io.FileReader;
import java.math.*;
import java.util.Scanner;
class FillGrid
{
public static void main(String[] args) throws IOException
{
String str = "";
//Opening the file and read the contents into a string str
File file = new File("input.in.txt");
try (FileReader fr = new FileReader(file))
{
char[] chars = new char[(int) file.length()];
fr.read(chars);
str = new String(chars);
}
catch (IOException e) {
e.printStackTrace();
}
//convert the string into a grid of characters
int l = str.length();
int k = 0, row, column,c;
row = (int) Math.floor(Math.sqrt(l));
column=(row-1)*2;
char s[][] = new char[row][column];
// convert the string into grid
for (int i = 0; i < row; i++)
{
c=column-1;
for (int j = 0; j < column; j++)
{
if(k < str.length())
{
if(i%2==0)
s[i][j] = str.charAt(k);
else
{
s[i][c]=str.charAt(k);
c--;
}
}
k++;
}
}
//Printing the encrypted string
char encrypt[][] = new char[column][row];
for (int i = 0; i < row-1; i++)
{
for (int j = 0; j < column; j++)
encrypt[j][i]=s[i][j];
}
for (int i = 0; i < column; i++)
{
for (int j = 0; j < row-1; j++) {
System.out.print(encrypt[i][j]);
}
}
}
}