d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Baby Names Java Help
Add Reply New Topic New Poll
Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
Nov 10 2014 07:56pm
Taking intro to java course and need help.

i need to write a method to search for and return a line to main from a txt file.

ex: of lines

Jax M 0 0 0 0 0 0 0 0 0 0 0 0 0 347
Randall M 731 974 620 650 467 369 232 70 59 100 136 192 440 841

User input :

name ? _________

gender ? ________

sample code from my program...

System.out.print("name? ");
String name = console.next().toLowerCase();
System.out.print("gender (M or F)? ");
String gender = console.next().toLowerCase();
while (input.hasNextLine()) {
String line = input.nextLine();
if ( ) {
return line;
}

i cant get it to work. any tips would be appreciated...

Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
Nov 11 2014 01:22am
got help via pm

thanks man

closed
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Nov 13 2014 07:45pm
Quote (Lightro @ Nov 10 2014 08:56pm)
Taking intro to java course and need help.

i need to write a method to  search for  and return a line to main from a txt file.

ex: of lines

Jax M 0 0 0 0 0 0 0 0 0 0 0 0 0 347
Randall M 731 974 620 650 467 369 232 70 59 100 136 192 440 841

User input :

name ?  _________

gender ? ________

sample code from my program...

System.out.print("name? ");
      String name = console.next().toLowerCase();
      System.out.print("gender (M or F)? ");
      String gender = console.next().toLowerCase();
      while (input.hasNextLine()) {
        String line = input.nextLine();
        if (                      ) { 
            return line;
        }

i cant get it to work. any tips would be appreciated...


Scanner input = new Scanner(filePath);
System.out.println("Name?");
String name = input.nextLine();
System.out.println("Gender (M or F)?: ");
String gender = input.nextLine();
//This is for testing
System.out.println("The name is: " + name + " and the gender is: " + gender);

Is that essentially the answer you got?
Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
Nov 15 2014 08:25pm
Quote (HoneyBadger @ Nov 13 2014 05:45pm)
Scanner input = new Scanner(filePath);
System.out.println("Name?");
String name = input.nextLine();
System.out.println("Gender (M or F)?: ");
String gender = input.nextLine();
//This is for testing
System.out.println("The name is: " + name + " and the gender is: " + gender);

Is that essentially the answer you got?


yeah pretty much...to create a scanner for the line i grab. and save the first and second token to strings and compare it to what the user typed

This post was edited by Lightro on Nov 15 2014 08:26pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll