日期:2014-05-20  浏览次数:20685 次

很基础的题,大家帮帮忙啊,谢谢了!
请分析以下命令及输出结果,编写类。
执行命令:                                             输出结果:
java   com.cn.A                                       Usage:java   com.cn.A   -sex   F|M
java   com.cn.A   -sex   F                         Today   is   2007年3月3日.Welcome,boy.
java   com.cn.A   -sex   M                         Today   is   2007年3月3日.Welcome,girl.

------解决方案--------------------
import java.util.Date;
import java.text.SimpleDateFormat;
class Test{
public static void main(String[] args){
int len = args.length;
if(len == 0){
System.out.println( "Usage:java com.cn.A -sex F|M ");
}else if(len == 1){
String str = null;
if(args[0].toString().equals( "F ")){
str = "Boy ";
}else if(args[0].toString().equals( "M ")){
str= "Girl ";
}
Date date = new Date();
SimpleDateFormat simDate = new SimpleDateFormat( "yyyy年M月d日 ");
String da = simDate.format(date);
System.out.println( "Today is "+ da + ".Welcome, " + str);
}

}

}
------解决方案--------------------
加一下包:
package com.cn;

import java.util.Date;
import java.text.SimpleDateFormat;
class A{
public static void main(String[] args){
int len = args.length;
if(len == 0){
System.out.println( "Usage:java com.cn.A -sex F|M ");
}else if(len == 1){
String str = null;
if(args[0].toString().equals( "F ")){
str = "Boy ";
}else if(args[0].toString().equals( "M ")){
str= "Girl ";
}
Date date = new Date();
SimpleDateFormat simDate = new SimpleDateFormat( "yyyy年M月d日 ");
String da = simDate.format(date);
System.out.println( "Today is "+ da + ".Welcome, " + str);
}

}

}