Problem with variable in class file.
Im working on a project from school where I read in a text file with numbers and print the max and the min. In my main file, I read in the text file and set the different numbers to variables a, b, and c. My question is, when Im writing my class file MaxMin, is there anyway to access those variables to compare them? Or will I have to do it some other way. Thanks for your help.
[386 byte] By [
Lidberga] at [2007-10-3 3:19:28]

Ok. Sorry
Here is the main code
import java.io.*;
import java.util.StringTokenizer;
public class LabAssign1
{
public static void main(String[] args) throws IOException
{
final int TOKENS_PER_LINE = 3;
String fileName = "labassign1.txt";
File theFile = new File(fileName);
FileInputStream theStream = new FileInputStream(theFile);
InputStreamReader theReader = new InputStreamReader(theStream);
BufferedReader input = new BufferedReader(theReader);
int numLines = 0;
String line = input.readLine();
while (line != null)
{
StringTokenizer st = new StringTokenizer(line);
if (line.length() == 3)
{
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
}
else
line = input.readLine();
}
input.close();
}
}
Is there any way to call variables a,b,and c in a separate class file?
This is one way, but you really should be instantiating objects rather than using static classes. It's not a good approach.
public class LabAssign1
{
static int a;
public static void main(String[] args)
{
// ...
a = 1;
Other.print();
}
}
class Other
{
static void print()
{
System.out.println(LabAssign1.a);
}
}