Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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]);                            
               }

       }  


   }
}

 

assignment_6.png


 

Assignment6.png  

Your program should work for any input file and any size grid. 3. Make sure your program only outputs the encrypted string. Check your solution to ensure that the output string is correct. 4. Make a video of your project. In your video, discuss your code and run your program. 5. Make sure program contains student name and statement of own work. Submit a text file in the digital classroom containing: a. Your program (.java) b. A link to your video

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Global Strategy

Authors: Mike W. Peng

5th Edition

0357512367, 978-0357512364

More Books

Students also viewed these Programming questions

Question

please explain step by step of the e - waste of ireland

Answered: 1 week ago