I see code above. I do NOT see a code.
Your prompt implies that the full name should be entered on one line.
name = read.next(); // reads the first word on that line
nameC = read.nextLine(); // reads ALL the remaining words on that line
nameA = read.nextLine(); // reads the 2nd line, which, if you hit enter, will blank.
You should use .next() to get the middle name and use .next() again to get the last name
Im trying to make a code with Java that prints out your first, middle and last name...I have t]used the string class and scanner...this is what i have so far
import java.util.Scanner;
public class JavaHW{
public static void main(String[] args){
Scanner read = new Scanner(System.in);
String name;
String nameA;
String nameC;
System.out.print("Please input your full nam: ");e
name = read.next();
nameC = read.nextLine();
nameA = read.nextLine();
System.out.println("Last Name: " + nameA);
System.out.println("Middle Name: " + nameC);
System.out.println("Name: " + name);
}//*End Main
}//*End class
At the moment of running it this is what it prints:
Please input your full name : Wendy Dianna Lopez
Blank**
Last Name Name: Blank**
Middle Name: Dianna Lopez
Name: Wendy
I need Lopez to be printed out on Last name without asking for a second variable....did I code something wrong?? I know I need a substring (thats what my teacher said) but I really don't know where or how to use it...any thoughts?
I need Dianna to be in middle name