Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to input username by getting the half of the first name and half of the last name and the day of the given birthday

example of output should be

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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: " + );
    
    

    
    
    }
    }

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading