In: Computer Science
AskInfoPrintInfo
Write a program called AskInfoPrintInfo. It should contain a class called AskInfoPrintInfo that contains the method main. The program should ask for information from the user and then print it. Look at the examples below and write your program so it produces the same input/output.
Examples
(the input from the user is in bold face) % java AskInfoPrintInfo enter your name: jon doe enter your address (first line): 23 infinite loop lane enter your address (second line): los angeles, ca, 90012 enter your phone number: (323) 555-1233 Name: jon doe address: 23 infinite loop lane los angeles, ca, 90012 Phone: (323) 555-1233 % java AskInfoPrintInfo enter your name: mary enter your address (first line): 123 grand ave, apt 230 enter your address (second line): New York, NY, 10001 enter your phone number: (212) 555 1234 Name: mary address: 123 grand ave, apt 230 New York, NY, 10001 Phone: (212) 555 1234 %
If you have any doubts, please give me comment...
import java.util.Scanner;
public class AskInfoPrintInfo{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String name, address1, address2, phone;
System.out.print("enter your name: ");
name = scnr.nextLine();
System.out.print("enter your address (first line): ");
address1 = scnr.nextLine();
System.out.print("enter your address (second line): ");
address2 = scnr.nextLine();
System.out.print("enter your phone number: ");
phone = scnr.nextLine();
System.out.println("Name: "+name);
System.out.println("address: "+address1+" "+address2);
System.out.println("Phone: "+phone);
}
}