成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

猜生日J(rèn)ava代碼 用java代碼編寫生日快樂

java編寫一個(gè)簡單的輸入生日計(jì)算下一個(gè)生日時(shí)間的代碼?

import java.util.Calendar;

專注于為中小企業(yè)提供網(wǎng)站建設(shè)、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)廣陽免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了超過千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

import java.util.Scanner;

import java.util.concurrent.TimeUnit;

/**

* Title: Test03.javabr

* Description:

*

* @author 王凱芳

* @date 2020年3月5日 下午6:03:04

* @version 1.0

*

* @request 編寫一個(gè)方法能計(jì)算任何一個(gè)人今天離他最近下一次生日還有多少天,然后在主方法(main方法)中輸入你的出生年月日,調(diào)用該方法的計(jì)算結(jié)果并輸出信息“某某同學(xué)離自己最近下一次生日x天”。

*/

public class Test03 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("請(qǐng)輸入你的姓名:");

String name = sc.nextLine();

System.out.println("請(qǐng)輸入你的生日,格式為(2000/01/01):");

String line = sc.nextLine();

String[] strs = line.split("/");

if (strs.length == 3) {

int days = getDays(strs[0], strs[1], strs[2]);

if (days == 0) {

System.out.println(String.format("%s 同學(xué),今天是你的生日,祝你生日快樂(#^.^#)", name, days));

} else {

System.out.println(String.format("%s 同學(xué)離自己最近下一次生日%d天。", name, days));

}

} else {

System.out.println("生日輸入不正確!請(qǐng)按格式輸入。");

}

sc.close();

}

/**

* 獲取最近一次生日天數(shù)

*

* @param year

* @param month

* @param day

* @return

*/

public static int getDays(String year, String month, String day) {

Calendar now = Calendar.getInstance();

now.set(Calendar.HOUR_OF_DAY, 0);

now.set(Calendar.MINUTE, 0);

now.set(Calendar.SECOND, 0);

now.set(Calendar.MILLISECOND, 0);

int now_year = now.get(Calendar.YEAR);

Calendar birthday = Calendar.getInstance();

birthday.set(Calendar.YEAR, now_year);

birthday.set(Calendar.MONTH, Integer.parseInt(month) - 1);

birthday.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));

birthday.set(Calendar.HOUR_OF_DAY, 0);

birthday.set(Calendar.MINUTE, 0);

birthday.set(Calendar.SECOND, 0);

birthday.set(Calendar.MILLISECOND, 0);

long diff = now.getTimeInMillis() - birthday.getTimeInMillis();

if (diff == 0) {

return 0;

} else if (diff 0) {

long diffDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);

return Math.abs((int) diffDays);

} else {

birthday.add(Calendar.YEAR, 1);

long diffMi = birthday.getTimeInMillis() - now.getTimeInMillis();

long diffDays = TimeUnit.DAYS.convert(diffMi, TimeUnit.MILLISECONDS);

return (int) diffDays;

}

}

}

用JAVA編程,輸入自己的生日,判斷自己生日是當(dāng)年中的第幾天和星期幾。

import java.io.*;

import java.util.*;

public class GetBirth {

int year = 0;

int month = 0;

int day = 0;

Calendar cld = Calendar.getInstance();//創(chuàng)建一個(gè)日歷

public GetBirth(){

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("請(qǐng)輸入年、月、日:");

try {

year = Integer.parseInt(in.readLine());

month = Integer.parseInt(in.readLine());

day = Integer.parseInt(in.readLine());

} catch (NumberFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

//將日歷時(shí)間設(shè)置成生日那天

public void setDate(int year,int month,int day){

cld.set(year,month-1,day);

}

//獲取該日是一年當(dāng)中的第幾天

public int getDay(){

return cld.get(6);

}

//獲取該日是星期幾

public String getDate(){

int date = cld.get(7);

return getWeekday(date);

}

//判斷解析一周7天的值

public String getWeekday(int dayofweek){

switch(dayofweek){

case 1: return "星期日";

case 2: return "星期一";

case 3: return "星期二";

case 4: return "星期三";

case 5: return "星期四";

case 6: return "星期五";

case 7: return "星期六";

default:return "error";

}

}

public static void main(String[] args) {

GetBirth gb = new GetBirth();

gb.setDate(gb.year, gb.month, gb.day);

System.out.println(gb.getDay());

System.out.println(gb.getDate());

}

}

希望對(duì)樓主有所幫助,謝謝。

JAVA猜生日的程序

不知道這個(gè)猜生日的程序具體難度如何,是否會(huì)使用很復(fù)雜的算法

在一般公司里面,一般不會(huì)用到復(fù)雜的算法的,需要的是對(duì)java基礎(chǔ)的掌握情況和其他的框架的知識(shí),所以你只需要掌握牢java基礎(chǔ)就好了

網(wǎng)站名稱:猜生日J(rèn)ava代碼 用java代碼編寫生日快樂
文章源于:http://jinyejixie.com/article38/hpcopp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站建設(shè)云服務(wù)器、搜索引擎優(yōu)化外貿(mào)網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
皋兰县| 浦江县| 当涂县| 日喀则市| 方城县| 婺源县| 甘洛县| 从江县| 大姚县| 荥经县| 德州市| 德化县| 高清| 乐都县| 天祝| 武宣县| 屏南县| 乐亭县| 阿勒泰市| 凤台县| 永仁县| 筠连县| 保德县| 遂宁市| 化德县| 宜都市| 买车| 五莲县| 壤塘县| 明星| 克山县| 娄底市| 姚安县| 洛川县| 辽宁省| 通许县| 达州市| 平度市| 瑞金市| 永清县| 大兴区|