package comssjswt;
import javautilScanner;
public class MyBirthday {
public static void main(String[] args) {
Systemoutprintln("请输入您的姓名");
Scanner scN=new Scanner(Systemin);
String name=scNnext();
Systemoutprintln("请输入生日的年:");
Scanner scY=new Scanner(Systemin);
int year=scYnextInt();
Systemoutprintln("请输入生日的月:");
Scanner scM=new Scanner(Systemin);
int month=scMnextInt();
Systemoutprintln("请输入生日的日:");
Scanner scD=new Scanner(Systemin);
int day=scDnextInt();
Systemoutprintln("");
Systemoutprintln("您的姓名为:"+name+"长度:"+namelength());
Systemoutprintln("生日的年是:"+(isLeapYear(year)"闰年":"平年"));
Systemoutprintln("生日的月是:"+getMonth(month));
Systemoutprintln("生日的天是:"+(day%2==0"偶数":"奇数"));
}
public static String getMonth(int m)
{
String months[]={"January","February","March","April","May","June",
"July","August","September","October","November","Decemeber"};
return months[m-1];
}
public static boolean isLeapYear(int y)
{
if(y%400 == 0 ||(y%4 == 0 && y%100 != 0))
{
return true;
}
return false;
}
}
输出:
请输入您的姓名
MaYaHoo
请输入生日的年:
2012
请输入生日的月:
12
请输入生日的日:
12
您的姓名为:MaYaHoo长度:7
生日的年是:闰年
生日的月是:Decemeber
生日的天是:偶数
import javautilScanner;
import javautilCalendar;
import javautilScanner;
public class Test {
public static void main(String[] args) {
Calendar time =CalendargetInstance();
Scanner scan=new Scanner(Systemin);
int Y,M,D;
Systemoutprintln("年:");
Y=scannextInt();
Systemoutprintln("月:");
M=scannextInt();
Systemoutprintln("日:");
D=scannextInt();
timeset(Y, M-1, D);
int Day=timeget(CalendarDAY_OF_WEEK);
Systemoutprintln("星期"+(Day-1));
}
}
注意,,这里每周是从星期天算起的,,,所以要减1
import javautilCalendar;
import javautilScanner;
import javautilconcurrentTimeUnit;
/
Title: Test03java<br>
Description:
@author 王凯芳
@date 2020年3月5日 下午6:03:04
@version 10
@request 编写一个方法能计算任何一个人今天离他最近下一次生日还有多少天,然后在主方法(main方法)中输入你的出生年月日,调用该方法的计算结果并输出信息“某某同学离自己最近下一次生日x天”。
/
public class Test03 {
public static void main(String[] args) {
Scanner sc = new Scanner(Systemin);
Systemoutprintln("请输入你的姓名:");
String name = scnextLine();
Systemoutprintln("请输入你的生日,格式为(2000/01/01):");
String line = scnextLine();
String[] strs = linesplit("/");
if (strslength == 3) {
int days = getDays(strs[0], strs[1], strs[2]);
if (days == 0) {
Systemoutprintln(Stringformat("%s 同学,今天是你的生日,祝你生日快乐(#^^#)", name, days));
} else {
Systemoutprintln(Stringformat("%s 同学离自己最近下一次生日%d天。", name, days));
}
} else {
Systemoutprintln("生日输入不正确!请按格式输入。");
}
scclose();
}
/
获取最近一次生日天数
@param year
@param month
@param day
@return
/
public static int getDays(String year, String month, String day) {
Calendar now = CalendargetInstance();
nowset(CalendarHOUR_OF_DAY, 0);
nowset(CalendarMINUTE, 0);
nowset(CalendarSECOND, 0);
nowset(CalendarMILLISECOND, 0);
int now_year = nowget(CalendarYEAR);
Calendar birthday = CalendargetInstance();
birthdayset(CalendarYEAR, now_year);
birthdayset(CalendarMONTH, IntegerparseInt(month) - 1);
birthdayset(CalendarDAY_OF_MONTH, IntegerparseInt(day));
birthdayset(CalendarHOUR_OF_DAY, 0);
birthdayset(CalendarMINUTE, 0);
birthdayset(CalendarSECOND, 0);
birthdayset(CalendarMILLISECOND, 0);
long diff = nowgetTimeInMillis() - birthdaygetTimeInMillis();
if (diff == 0) {
return 0;
} else if (diff < 0) {
long diffDays = TimeUnitDAYSconvert(diff, TimeUnitMILLISECONDS);
return Mathabs((int) diffDays);
} else {
birthdayadd(CalendarYEAR, 1);
long diffMi = birthdaygetTimeInMillis() - nowgetTimeInMillis();
long diffDays = TimeUnitDAYSconvert(diffMi, TimeUnitMILLISECONDS);
return (int) diffDays;
}
}
}
以上就是关于设计一个JAVA程序myBirthday类的要求得到用户名字的长度,和关于生日的年月日的信息全部的内容,包括:设计一个JAVA程序myBirthday类的要求得到用户名字的长度,和关于生日的年月日的信息、java编写程序求出你的生日那天是星期几、java编写一个简单的输入生日计算下一个生日时间的代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)