please help thank you in advance!!
the output of the code in username should be the 2 letter in firt name and 3 in last name and date number
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter Fullname:");
String fullname = sc.nextLine();
System.out.println("Enter Birthday : ");
String bday = sc.nextLine();
System.out.println("Your Login Details");
System.out.println("Enter Fullname:" fullname);
System.out.println("Enter Birthday : " bday);
System.out.println("Enter Username: " );
}
}
CodePudding user response:
Assuming the input will always be in the format you provided, you can use String.split()
and String.substring()
to extract the required information from the input as shown below.
String[] splitName = fullName.split(" ");
String firstName = splitName[0];
String lastName = splitName[1];
String day = bday.split("-")[1];
String username = firstName.substring(0, 2) lastName.substring(0, 3) day;
CodePudding user response:
String[] firstLastName = fullname.split(" ");
System.out.println("Enter Username: " firstLastName[0].substring(0, 2) firstLastName[1].substring(0, 3) bday.split("-")[1]);