-
ReadFromFile.java
-
import java.io.*;
import java.sql.*;
public class ReadFromFile
{
public static void main (String [] args) throws IOException
{
BufferedReader fromFile = new BufferedReader(new FileReader("Guest.txt"));
int a = 2000;
String [] sex = new String [a];
for (int i = 0; i < 2; i ++)
{
sex[i] = fromFile.readLine();
System.out.println ("Customer Sex: " +sex[i]);
}
}
}
-
Guest.txt
-
MR Alex 30
MS Alice 20
-
Output
-
MR Alex 30
MS Alice 20
The above is the java file & txt file. It can read the file, but the output i want is:
-
expected output
-
Sex: Male
Name: Alex
Age: 30
Sex: Female
Name: Alice
Age: 20
If MR, MSTR will have sex = Male. If MRS, MDM, MS will have sex = Female.
Other than that, i also like to put the Male/Female into String sex, put the name into String name, and age into int age.
How i can do all of these?
2007-08-15
17:20:32
·
2 answers
·
asked by
scottcky1985
3
in
Programming & Design