d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Help (beginner) > Topic
Add Reply New Topic New Poll
Member
Posts: 2,092
Joined: Nov 22 2006
Gold: 433.69
Apr 19 2015 02:52pm
http://gyazo.com/64c9a4a6c7feba8a3b7adf0a1ce94394

how do i code this.. i am stuck on how to read the file and put the individual int and chars into the 2d array as elemnts. since both two different variables. I would post what i have so far but i do not have anything been staring at net beans for quite some time.. also been googling/youtubing for a while :(
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 19 2015 03:46pm
when you say "int and char" , do you mean like how the following line has numbers and characters in it?


Code
Adsdfdkf23jkdfksf234543fdf



?

Just interpret everything as a character and fill a 64x64 array of characters. Nothing in the assignment seems to indicate you would have to specifically interpret the numbers as an integer type.


This seems (at quick glance) like you just use a buffered reader to take the file into an array of 64x64, then depending on what the command string is, for each command perform some kind of matrix modification

Forgive me if I am not 100% correct on the java side I/O. I have not touched it since I finished college several months ago :p

This post was edited by Eep on Apr 19 2015 03:57pm
Member
Posts: 2,092
Joined: Nov 22 2006
Gold: 433.69
Apr 19 2015 04:09pm
ok so the numbers in the file when being initialized doesn't need a separate int declaration? becuase i need to input a .txt file in there which consists of both int and char types. and to answer your question yes. this is where im a bit confused upon.

This post was edited by cKranez on Apr 19 2015 04:15pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 19 2015 04:44pm
Quote (cKranez @ Apr 19 2015 05:09pm)
ok so the numbers in the file when being initialized doesn't need a separate int declaration? becuase i need to input a .txt file in there which consists of both int and char types. and to answer your question yes. this is where im a bit confused upon.


right. Your 64x64 array should be an array of characters
Member
Posts: 2,092
Joined: Nov 22 2006
Gold: 433.69
Apr 19 2015 04:47pm
do i have to convert the int to char first?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 19 2015 04:50pm
Quote (cKranez @ Apr 19 2015 05:47pm)
do i have to convert the int to char first?


you shouldn't have to. Java's built in IO functions should take care of the reading for you.
Member
Posts: 2,092
Joined: Nov 22 2006
Gold: 433.69
Apr 19 2015 04:58pm
sigh.. can u somehow give me an example of how might it look :( ... ? sorry im at a block right now. on how to do this part..

so far...

Code
import java.util.Scanner;

public class project1 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

char[][] charArray = new char[];
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Apr 19 2015 05:19pm
Quote (cKranez @ Apr 19 2015 05:58pm)
sigh.. can u somehow give me an example of how might it look :( ... ? sorry im at a block right now. on how to do this part..

so far...

Code
import java.util.Scanner;

public class project1 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

char[][] charArray = new char[];



Create a File object to represent your file, new up a Scanner object and hook it up to read from your file. Fill in your array of characters.

Once you have that done, maybe iterate over the array to make sure it looks correct. Then figure out how to transform it based on the commands.
Member
Posts: 2,092
Joined: Nov 22 2006
Gold: 433.69
Apr 19 2015 06:03pm
ok see thats the thing how do i amke it so i dont have to represent a certain file? meaning.. my instructor can put in a file of his own and it'll do the same?.. how do i define the variables for nRows /nCols?

Code
import java.util.Scanner;

public class project1 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
{
char[][] charAr = new char[nRows][nCols];


This post was edited by cKranez on Apr 19 2015 06:03pm
Member
Posts: 2,059
Joined: Aug 16 2013
Gold: 0.80
Apr 24 2015 10:37pm
Can you copy and paste the file here? I don't know if that will alter the structure of the file. Or try uploading the file so I can download it.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll