asked 132k views
3 votes
Write a program that asks the user to input their first and last names. The first prompt should state: Please input your first name: The second prompt should state: Please input your last name:

asked
User Dpetrini
by
8.7k points

1 Answer

7 votes

Answer:

Program in c++ and java

Step-by-step explanation:

C++ Code

#include<iostream> //for input and output

#include <string> // for string

using namespace std;

int main()

{

string firstname;

string lastname;

cout<<"Please input your first name :";

cin>> firstname;

cout<<"Please input your last name :";

cin>> lastname;

cout<< "Your name is "<< firstname << " "<<lastname;

// declaring output string stream

return 0;

}

Java Code

import java.util.Scanner;

public class SquareRoot {

public static void main(String[] args){

Scanner scanner = new Scanner(System.in);

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

String firstName = scanner.next();

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

String lastname = scanner.next();

System.out.println("Your name is "+firstName+" "+lastname);

}

}

Output

Please input your first name :John

Please input your last name :Stone

Your name is John Stone

answered
User Pavon
by
8.2k points

No related questions found