asked 204k views
5 votes
I need help with this java question.

In java,
The examples are exactly that examples, the code should make it
so the inputs and outputs match.
Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of th

1 Answer

6 votes

Answer:

Step-by-step explanation:

import java.util.Scanner;

public class LoginNameGenerator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Input first name, last name, and a four-digit integer

System.out.print("Enter your first name: ");

String firstName = scanner.nextLine();

System.out.print("Enter your last name: ");

String lastName = scanner.nextLine();

System.out.print("Enter a four-digit integer: ");

int fourDigitInteger = scanner.nextInt();

scanner.close();

// Generate the login name

String loginName = generateLoginName(firstName, lastName, fourDigitInteger);

// Output the login name

System.out.println("Your login name is: " + loginName);

}

public static String generateLoginName(String firstName, String lastName, int fourDigitInteger) {

// Get the first five letters of the last name

String lastNamePrefix = lastName.substring(0, Math.min(lastName.length(), 5));

// Create the login name by combining the first name, last name prefix, and four-digit integer

String loginName = firstName.toLowerCase() + lastNamePrefix.toLowerCase() + fourDigitInteger;

return loginName;

}

}

This program first takes the user's first name, last name, and a four-digit integer as input, then uses the generateLoginName method to generate the login name by combining the first name, the first five letters of the last name, and the four-digit integer. Finally, it outputs the login name.

answered
User Jameo
by
8.6k points