In: Computer Science
Program should be written in Java
b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out class or the JOptionPane classes as you desire. The purpose of this exercise is practice for concatenating Strings and producing String output.
Java Program:
import java.util.*;
class AnswerParagraph
{
//Main method
public static void main(String[] args)
{
//Creating Scanner object
Scanner reader = new
Scanner(System.in);
//Reading answers from user
System.out.print("\nWhat is your
city of birth? ");
String birthCity =
reader.nextLine();
System.out.print("What is your
favorite sport? ");
String favSport =
reader.nextLine();
System.out.print("If you could live
anywhere in the world, where would you like to live? ");
String livePlace =
reader.nextLine();
System.out.print("What is your
dream vacation? ");
String dreamVacation =
reader.nextLine();
//Constructing output string
String output = "Hello All, I was
born in " + birthCity + " but I would like to live in " + livePlace
+ ". My favorite sport was " + favSport + ". My dream vacation is "
+ dreamVacation;
//Printing output string
System.out.println("\n" + output +
"\n");
}
}
__________________________________________________________________________________________
Sample Run: