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.

Answer :

ijeggs

Answer:

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:

  1. Using Java programming language
  2. Import Scanner class to receive user input and Random class to generate random number
  3. Prompt user for first and last name separately and store in variables firstName and lastName.
  4. Extract the first character of the firstname char firstLetter = firstName.charAt(0);
  5. Extract the first five characters of the last name String firstFiveLetters = lastName.substring(0,5);
  6. Concatenate the two extracted values and output
  7. Generate a random number between 10 and 99 and output.
  8. 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

Answer:

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.

Other Questions