Hey everybody. I working on a project for school that is due may 3rd, and right now I'm trying to turn the elements of a String array into integer values. please help me, i know it is only two or three lines of code at max but i just can't figure it out. Any help you can offer is deeply Appreciated, thanks.
for info on the project i working on go to: http://www.cs.uncc.edu/~rilson/2215/assignments/KnapEncrypt Instructions S05.html
here is my code so far, i am trying to turn the elements of encryptvalue[] into integers in the first while loop.
---------------------------------------------------------------------------
import java.util.*;
import java.io.*;
public class KnapEncrypt
{
public static void main (String[] args)throws java.io.IOException
{
FileReader fr = new FileReader (args[0]);
BufferedReader inFile = new BufferedReader (fr);
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
String line = inFile.readLine();
int value_index;
StringTokenizer tokens = new StringTokenizer(line);
String[] encryptvalue = new String[tokens.countTokens()];
int converted;
int total = 0;
value_index = 0;
int line_index = 0;
while (value_index < encryptvalue.length)
{
Integer.parseInt(encryptvalue[value_index]);
encryptvalue[value_index] = tokens.nextToken();
System.out.print(encryptvalue[value_index] + " ");
value_index++;
}
total = encryptvalue[1] + encryptvalue[0];
System.out.println(total);
/* ignore this stuff (for now)
while((line = inFile.readLine()) != null && line.length() != 0)
{
if (line.length() == 10)
{
System.out.println("input: " + line);
if (line.charAt(line_index) == '1')
{
total = total + encryptvalue[line_index];
}
else
{
total = total + 0;
}
System.out.println("output: " + total);
}
else
{
System.out.println("input: " + line);
}
line_index++;
}
*/
}
}
for info on the project i working on go to: http://www.cs.uncc.edu/~rilson/2215/assignments/KnapEncrypt Instructions S05.html
here is my code so far, i am trying to turn the elements of encryptvalue[] into integers in the first while loop.
---------------------------------------------------------------------------
import java.util.*;
import java.io.*;
public class KnapEncrypt
{
public static void main (String[] args)throws java.io.IOException
{
FileReader fr = new FileReader (args[0]);
BufferedReader inFile = new BufferedReader (fr);
BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
String line = inFile.readLine();
int value_index;
StringTokenizer tokens = new StringTokenizer(line);
String[] encryptvalue = new String[tokens.countTokens()];
int converted;
int total = 0;
value_index = 0;
int line_index = 0;
while (value_index < encryptvalue.length)
{
Integer.parseInt(encryptvalue[value_index]);
encryptvalue[value_index] = tokens.nextToken();
System.out.print(encryptvalue[value_index] + " ");
value_index++;
}
total = encryptvalue[1] + encryptvalue[0];
System.out.println(total);
/* ignore this stuff (for now)
while((line = inFile.readLine()) != null && line.length() != 0)
{
if (line.length() == 10)
{
System.out.println("input: " + line);
if (line.charAt(line_index) == '1')
{
total = total + encryptvalue[line_index];
}
else
{
total = total + 0;
}
System.out.println("output: " + total);
}
else
{
System.out.println("input: " + line);
}
line_index++;
}
*/
}
}