网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java代码系统接收天数 java计算接口调用时间

java 获取某月份的具体天数

楼上正解,不过楼主问出这个问题可能也是初学者,我就提供一下用简单语法的代码吧

余庆网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联建站于2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

public static void main(String[] args) {

Scanner scan=new Scanner(System.in);

System.out.println("请输入年份");

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

System.out.println("请输入月份");

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+"月的天数为:"+31);

break;

case 4:

case 6:

case 9:

case 11:

System.out.println(year+"年"+month+"月的天数为:"+30);

case 2:

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

System.out.println(year+"年2月的天数为:"+29);

}else{

System.out.println(year+"年2月的天数为:"+28);

}

}

}

如何写Java程序来接受用户输入的一个1-12之间的整数,用switch语句输出对应月份的天数?

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("请输入要查询的月份:");

num=sc.nextInt();

if(num12 ||num1){

System.out.println("你输入的月份错误,请重新输入");

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+"'月对应的天数是:'"+dayOfMonth+"'或者29");

}

else{

System.out.println("'"+num+"'月对应的天数是:'"+dayOfMonth+"'");

}

System.out.println("C为继续,其余任意键退出!");

String t=sc.next();

if(t!="c"){

really=false;

}

}

}

}//(楼主如果需要判断闰年的话给发个悄悄话,这是为2月准备的)

编写一个Java程序,接受用户输入的一个1-12之间的整数,利用switch语句输出对应月份的天数

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("请输入月份:");

Scanner scan=new Scanner(System.in);

temp=scan.nextInt();

sw.contains(temp);

}

}

楼主,别忘了给分哦~~~

用java程序写出 接收一个年份和一个月份,判断得出该月的总天数。(用if语句完成)

import java.util.*;

public class Test {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("请输入年份");

int year = input.nextInt();

System.out.println("请输入月份");

int month = input.nextInt();

if(month==2){

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

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

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

return;

}else {

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

return;

}

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

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

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

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

}

}

}


当前标题:java代码系统接收天数 java计算接口调用时间
文章位置:http://bjjierui.cn/article/dogiehp.html

其他资讯