一个JAVA小程序,哪位牛人帮个忙

来源:百度知道 编辑:UC知道 时间:2024/05/15 19:01:36
In this exercise, we will use the Scanner class to read in a series of values from a user and print it out
to screen in a specific format.
Your task is to write a program that will prompt and read from the user details in the following
sequence:
• Surname
• First Name
• Year born
• Country of Birth
Your program should output the information in the following format:
Please enter your surname: Sparrow
Please enter your first name: Jack
Please enter the year you were born: 1969
Please enter your country of birth: Australia
Hi Jack Sparrow, you're 39 this year and you were born in Australia.

这个很简单阿 :
import java.util.Date;
import java.util.Scanner;
public class Test04{
public static void main(String[]args){
Date date=new Date();
String year=date.toString();
year=year.substring(year.length()-4);
int age=Integer.parseInt(year);
Scanner input=new Scanner(System.in);
System.out.println("Please enter your surname:");
String name=input.nextLine();
System.out.println("Please enter your first name:");
String fName=input.nextLine();
System.out.println("Please enter the year you were born:");
String brith=input.nextLine();
System.out.println("Please enter your country of birth:");
String coun=input.nextLine();
System.out.print("Hi "+fName+" "+name+","+"you're ");
System.out.print(age-Integer.parseInt(brith));
System.out.print(" this year and you were born in &qu