Ask Question
4 March, 18:04

Write a program that prompts for and reads the user's first and last name (separately). Then print a string composed of the first letter of the user's first name, followed by the first five characters of the user's last name, followed by a random number in the range 10 to 99.

+2
Answers (2)
  1. 4 March, 20:01
    0
    import random

    first_name = input ("write your first name: ")

    last_name = input ("write your last name: ")

    x = first_name[0]

    y = last_name[0:5]

    z = random. randrange (10, 99)

    print (x + y + str (z))

    Explanation:

    The code is written in python

    first_name = input ("write your first name: ")

    The code prompt the user to input his/her first name.

    last_name = input ("write your last name: ")

    The code prompt the user to input his/her last name.

    x = first_name[0]

    This code brings out the first letter of the users first name.

    y = last_name[0:5]

    This code brings out the users first five characters of the user last name.

    z = random. randrange (10, 99)

    The code generate a random number from range 10 to 99.

    print (x + y + str (z))

    The first letter of the first name, followed by the first five characters of the user's last name, followed by the random number generated is displayed with the print function.
  2. 4 March, 21:40
    0
    import java. util. Random;

    import java. util. Scanner;

    public class num14 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter Your first Name");

    String firstName = in. next ();

    System. out. println ("Enter Your Last Name");

    String lastName = in. next ();

    char firstLetter = firstName. charAt (0);

    String firstFiveLetters = lastName. substring (0,5);

    System. out. print (firstLetter+firstFiveLetters);

    Random rand = new Random ();

    int randomNum = rand. nextInt (100) + 10;

    System. out. println (randomNum);

    }

    }

    Explanation:

    Using Java programming language Import Scanner class to receive user input and Random class to generate random number Prompt user for first and last name separately and store in variables firstName and lastName. Extract the first character of the firstname char firstLetter = firstName. charAt (0); Extract the first five characters of the last name String firstFiveLetters = lastName. substring (0,5); Concatenate the two extracted values and output Generate a random number between 10 and 99 and output. Observe that the random number utilizes a non-inclusive upperbound. that is rand. nextInt (100) will generate numbers from 0-99. We add 10 to this value to ensure it is between 10-99
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that prompts for and reads the user's first and last name (separately). Then print a string composed of the first letter of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers