- 14
- 0
- 约3.11千字
- 约 4页
- 2020-11-23 发布于山东
- 举报
辽宁工程技术大学上机实验报告
成绩
实验名称
Java字符串
院系
理学院
专业
理科实验班
班级
理科 13-1 班
姓名
学号
日期
2015.4.2
实验
简述本次实验目的:
( 1)掌握正则表达式的使用。
( 2)熟悉 java 的字符串。
目的
我查阅了大量的资料和信息,并与同学们进行了激烈的讨论。
实验
准备
实验
3 个练习,完成
3个。
本次共有
进度
本次实验的收获、体会、经验、问题和教训:
经过了本次的实验, 使我对 java 的开发环境和运行环境有了一定的了解。 通过这次实验,我收获很多。在自己编程过程中发现许多错误,也认识到自己在某
些方面还存在不足,需要多多练习。
实验
总结
教师
评语
实验内容:
精选文库
1)用命令行方式提供 1 至 3 个整数, 按顺序分别为年、 月、日数据。 若仅提供一个整数,则为年号,程序判断该年是否为闰年;若提供两个整数,则为年号、月号,程序输出为该
年月的天数;若提供三个整数,则为年、月、日数据,程序输出这一天是星期几。若未提供任何数据或提供的数据个数超过三个,则程序输出出错信息并给出程序的使用方法。
程序如下:
public class Date {
public static int MonthDay( int year, int month){
int n=0;
if (month==1||month==3||month==5||month==7||month==8||month==10||month==
12) n=31;
else if (month==2){ if (year%400==0||(year%4==0year%100!=0)) n=29;
else n=28;}
else n=30;
return n;
}
public static void main(String[] args) {
int year,month,day,len,bool=0,n,i,a,b=0,c;
len=args. length ;
if (len1||len3){
System. out .println( 您输入的参数个数错误! );
System. out .println( 请重新启动程序, 并用命令行方式提供 1 至 3 个整数参数 );
}
else {
switch (len)
{ case 1:year=Integer. parseInt (args[0]);
if (year%400==0||(year%4==0year%100!=0))
System. out .println(year+ 是闰年。 );
else
System. out .println(year+ 是平年。 ); break ;
case 2:year=Integer. parseInt (args[0]);
month=Integer. parseInt (args[1]);
n= MonthDay (year,month);
System. out .println(year+ 年 +month+ 月有 +n+ 天。 ); break ;
case 3:year=Integer. parseInt (args[0]);
month=Integer. parseInt (args[1]);
day=Integer. parseInt (args[2]);
a=year+(year-1)/4-(year-1)/100+(year-1)/400;
for (i=1;i=month-1;i++)
b=b+ MonthDay (year,i);
a=(a+b+day-1)%7;
switch (a)
{ case 0:System. out .println(year+ 年 +month+ 月 +day+ 日是星期
天. );; break ;
— 2
精选文库
case 1:System. out .println(year+ 年 +month+ 月 +day+ 日是星期
一. ); break ;
case 2:System. out .println(year+ 年 +month+ 月 +day+ 日是星期
二. ); break ;
case 3:System. out .println(year+ 年 +month+ 月 +day+ 日是星期
三. ); break ;
case 4:System. out .println(year+ 年 +month+ 月 +day+ 日是星期
四. ); break ;
case 5:Sys
原创力文档

文档评论(0)