I am writing a program where the user inputs their forename and surname with space inbetween all on one line. The program will then detect the space and extract the forename and surname into different variables to be printed out.
Example: Say a user entered "simon hall" on one line There is space inbetween and I want it outpuuted like this: Forename: Simon Surname: Hall
My code(pretty much useless right now): (Input/Output Below)
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Input forename and surname on one line (space included)");
String fullName = scanner.next();
String result = fullName;
result = result.split(" ") [0];
System.out.println(result);
}
}
**Input: zayaan khan (on one line)
Output:
zayaan** (I want to print Forename: Zayaan Surname: Khan )
Thank you ;)