java - nextLine() and next() giving blanks when naming object -


After using the next () to leave an additional line after a user entry, I am trying and next The line () is the name that the user is currently entering. My program is using a text based menu and this is the only way I have been able to make the menu flow smoothly (with the Do-All Loop and what you have but I retract) My problem is : While I know that the object I am trying to name is receiving data from my main method, it is not giving proper name, just giving it a blank character I know this Because this object's name changes, but it does not change the object correctly, it just gives it in one place (I give the name variable for the object "N / A" object in the constructor method). How can I deal with this problem now and in the future?

Main method snippet

  string past; Selector = in.nextInt (); If (selector == 1) {System.out.print ("please enter last name:"); Next (); Last = in. NXtine (); Entry.setLast (last); Terminator = true; }   

object naming method

  private constant string last_name; Public Static String Setlist (String A) {last_name = a; Return to Last_name; }   

It looks like a simple problem but I want some outside perspective! I do not think IM focuses on the right issue here. Thanks

The problem is right here:

  in.next () ; Last = in. NXtine (); Entry.setLast (last);   

in.next (); The line will first read the available tonen (sequence of non-VVSpace characters) and drop it from the input.

final = in.nextLine (); saves the rest of the current line in the string, but the last name you want is already discarded, so there is nothing left in it. The first letter in the input that looks in.nextLine () will be a new row, so it only gives an empty string as if there was nothing in the line.

You want to save the string back by .next (), not inside .nextLine () as follows:

  last = in.next (); In.nextLine (); Entry.setLast (last);    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -