Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing a CSV string and using elements of the string for computation- homework
    primarykey
    data
    text
    <p>I am very new to java, and this is homework. Any direction would be appreciated. The assignment is to read an external text file and then parse that file to produce a new file. The external file looks something like this:</p> <pre><code>2 //number of lines in the file 3,+,4,*,2,-. 5,*,2,T,1,+ </code></pre> <p>I have to read this file and produce an output that takes the preceding int value and prints the following character (skipping the comma). So the output would look like this:</p> <pre><code>+++****-- *****TT+ </code></pre> <p>I have tried to setup my code using two methods. The first to read the external file (passed as a parameter) which, as long as there is a next line, will call a second method, processLine, to parse the line. This is where I am lost. I can't figure out how this method should be structured so it reads the line and interprets the token values as either ints or chars, and then executes code based on those values. I am only able to use what we have covered in class, so no external libraries, just the basics.</p> <pre><code>public static void numToImageRep(File input, File output) //rcv file throws FileNotFoundException { Scanner read = new Scanner(input); while(read.hasNextLine()){ //read file line by line String data = read.nextLine(); processLine(data); //pass line for processing } } public static void processLine(String text){ //incomplete, all falls apart here. Scanner process = new Scanner(text); while(process.hasNext()){ if(process.hasNextInt()){ int multi = process.nextInt(); } if(process.hasNext()==','){ } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload