java代碼系統(tǒng)接收天數(shù) java計(jì)算接口調(diào)用時(shí)間

java 獲取某月份的具體天數(shù)

樓上正解,不過(guò)樓主問(wèn)出這個(gè)問(wèn)題可能也是初學(xué)者,我就提供一下用簡(jiǎn)單語(yǔ)法的代碼吧

余慶網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站開發(fā)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)建站于2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。

public static void main(String[] args) {

Scanner scan=new Scanner(System.in);

System.out.println("請(qǐng)輸入年份");

int year= scan.nextInt();//得到需求年份

System.out.println("請(qǐng)輸入月份");

int month=scan.nextInt();//得到需求月份

switch(month){

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

System.out.println(year+"年"+month+"月的天數(shù)為:"+31);

break;

case 4:

case 6:

case 9:

case 11:

System.out.println(year+"年"+month+"月的天數(shù)為:"+30);

case 2:

if((year%400)==0 || ((year%4)==0)((year%100)!=0)){

System.out.println(year+"年2月的天數(shù)為:"+29);

}else{

System.out.println(year+"年2月的天數(shù)為:"+28);

}

}

}

如何寫Java程序來(lái)接受用戶輸入的一個(gè)1-12之間的整數(shù),用switch語(yǔ)句輸出對(duì)應(yīng)月份的天數(shù)?

import java.util.Scanner;

public class QuestionOne {

private static boolean start;

public static void main(String[] args) {

boolean really=true;

Scanner sc=new Scanner(System.in);

while(really=true){

boolean temp=true;

int num=0;

start:

while(temp==true){

System.out.print("請(qǐng)輸入要查詢的月份:");

num=sc.nextInt();

if(num12 ||num1){

System.out.println("你輸入的月份錯(cuò)誤,請(qǐng)重新輸入");

continue;

}

temp=false;

}

int dayOfMonth = 0;

switch (num) {

case 1:

dayOfMonth=31;

break;

case 2:

dayOfMonth=28;

break;

case 3:

dayOfMonth=31;

break;

case 4:

dayOfMonth=30;

break;

case 5:

dayOfMonth=31;

break;

case 6:

dayOfMonth=30;

break;

case 7:

dayOfMonth=31;

break;

case 8:

dayOfMonth=31;

break;

case 9:

dayOfMonth=30;

break;

case 10:

dayOfMonth=31;

break;

case 11:

dayOfMonth=30;

break;

case 12:

dayOfMonth=31;

break;

default:

break;

}

if(num==2){

System.out.println("'"+num+"'月對(duì)應(yīng)的天數(shù)是:'"+dayOfMonth+"'或者29");

}

else{

System.out.println("'"+num+"'月對(duì)應(yīng)的天數(shù)是:'"+dayOfMonth+"'");

}

System.out.println("C為繼續(xù),其余任意鍵退出!");

String t=sc.next();

if(t!="c"){

really=false;

}

}

}

}//(樓主如果需要判斷閏年的話給發(fā)個(gè)悄悄話,這是為2月準(zhǔn)備的)

編寫一個(gè)Java程序,接受用戶輸入的一個(gè)1-12之間的整數(shù),利用switch語(yǔ)句輸出對(duì)應(yīng)月份的天數(shù)

import java.util.Scanner;

class Switch{

public void contains(int temp){

switch(temp){

case 1:{

System.out.println(""+temp+"月為31天?。?!");

break;

}

case 2:{

System.out.println(""+temp+"月為28天!??!");

break;

}

case 3:{

System.out.println(""+temp+"月為31天!??!");

break;

}

case 4:{

System.out.println(""+temp+"月為30天!?。?);

break;

}

case 5:{

System.out.println(""+temp+"月為31天?。?!");

break;

}

case 6:{

System.out.println(""+temp+"月為30天!?。?);

break;

}

case 7:{

System.out.println(""+temp+"月為31天?。。?);

break;

}

case 8:{

System.out.println(""+temp+"月為31天?。。?);

break;

}

case 9:{

System.out.println(""+temp+"月為30天?。?!");

break;

}

case 10:{

System.out.println(""+temp+"月為31天?。。?);

break;

}

case 11:{

System.out.println(""+temp+"月為30天?。?!");

break;

}

case 12:{

System.out.println(""+temp+"月為31天?。?!");

break;

}

default:{

System.out.println("輸入的月份有誤?。?!");

break;

}

}

}

}

public class SwitchDemo{

public static void main(String args[]){

int temp=0;

Switch sw=new Switch();

System.out.print("請(qǐng)輸入月份:");

Scanner scan=new Scanner(System.in);

temp=scan.nextInt();

sw.contains(temp);

}

}

樓主,別忘了給分哦~~~

用java程序?qū)懗?接收一個(gè)年份和一個(gè)月份,判斷得出該月的總天數(shù)。(用if語(yǔ)句完成)

import java.util.*;

public class Test {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("請(qǐng)輸入年份");

int year = input.nextInt();

System.out.println("請(qǐng)輸入月份");

int month = input.nextInt();

if(month==2){

if (((year % 100 == 0) (year % 400 == 0))

|| ((year % 100 != 0) (year % 4 == 0))) {

System.out.println(month+"月份天數(shù)是29天");

return;

}else {

System.out.println(month+"月份天數(shù)是28天");

return;

}

}else if(month%2==0 ) {

System.out.println(month+"月份是30天");

}else if(month%2!=0) {

System.out.println(month+"月份是31天");

}

}

}

本文名稱:java代碼系統(tǒng)接收天數(shù) java計(jì)算接口調(diào)用時(shí)間
文章地址:http://muchs.cn/article48/dogiehp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、小程序開發(fā)、網(wǎng)站設(shè)計(jì)關(guān)鍵詞優(yōu)化、網(wǎng)站內(nèi)鏈、面包屑導(dǎo)航

廣告

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

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)