i want Use the 2 text files boynames.txt and girlnames.txt Prompt the user for boy or girl and then for a letter from the alphabet. Open either boynames.txt or girlnames.txt and read each line in – when the name starts with the letter that the user specified then write the name and the number to an output file. And I want it output file an appropriate name such as boyJ.txt or girlA.txt. boyJ.txt will look something like this:
Jacob 29195
Joshua 24950
Joseph 21265
-------------------
i have a problem with the code , i want to input of the boy name that start from " J " like example above but it does not work. and it show all the name . so how can i write the code that input the frist letter of the name and it show all the name that start with that letter ?
so i hope anyone can help me thank.
thiis my code
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class demo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Scanner inputStream= null;
String line = null;
System.out.println("Please enter name:");
line = keyboard.nextLine( );
try
{
inputStream =
new Scanner(new FileInputStream("boynames.txt"));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file ");
System.exit(0);
}
while(inputStream.hasNextLine()){
line=inputStream.nextLine();
System.out.println("boy name "+ line );
}
inputStream.close( );
}
}