Write an application that asks the user to enter his/her first name, last name,
ID: 3876240 • Letter: W
Question
Write an application that asks the user to enter his/her first name, last name, birthday, and where you born (all fields type String) and prints their information to the console. The application should use printf. Remember to use the class Scanner and the method next() or nextLine() for Stringfields. Pleas submit four files, two source codes (.java extension) and two bytecodes (.class extension). The output must be something like these: __________________________________________________________ Welcome! What is your first name? John What is your last name? Torres When is your birthday? 08/12/1980 Where did you born? Mexico Display my info: First Name: John Last Name: Torres Birthday : 08/12/1980 Born in : Mexico
Explanation / Answer
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// Declaring variables
Scanner sc = new Scanner(System.in);
String fname, lname, birthday, born;
System.out.println("___________________________ Welcome!");
// taking user input of first name
System.out.print("What is your first name? ");
fname = sc.next();
// taking user input of last name
System.out.print("What is your last name? ");
lname = sc.next();
// // taking user input of birthday
System.out.print("When is your birthday? ");
birthday = sc.next();
// taking user input of where user born
System.out.print("Where did you born? ");
born = sc.next();
// printing output
System.out.println(" My Info");
System.out.printf("First Name: %s ",fname);
System.out.printf("Last Name: %s ",lname);
System.out.printf("Birthday: %s ",birthday);
System.out.printf("Born in: %s ",born);
}
}
/* SAMPLE output
___________________________ Welcome!
What is your first name? John
What is your last name? Torres
When is your birthday? 08/01/1998
Where did you born? Mexico
My Info
First Name: John
Last Name: Torres
Birthday: 08/01/1998
Born in: Mexico
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.