java计算当前月工作日天数(Java从键盘上输入一个月份)

输入6,今天小编就来聊一聊关于java计算当前月工作日天数?接下来我们就一起去研究一下吧!

java计算当前月工作日天数(Java从键盘上输入一个月份)

java计算当前月工作日天数

输入

6

输出

6月份为30天

这是对的

package com;

import java.io.*;

public class app4_4 {

public static void main(String[] args)throws Exception

{

int days;int month;

BufferedReader buf;

InputStreamReader inp;

inp=new InputStreamReader(System.in);

buf=new BufferedReader(inp);

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

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

switch((int)month) {

case 2:

days = 28;

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days = 31;

break;

default:

days = 30;

}

System.out.println(month "月份为" days "天");

}

}

错误示范

package com;

public class app4_4 {

public static void main(String[] args)throws Exception

{

int days;char month;

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

month=(char)System.in.read();

switch(month) {

case 2:

days = 28;

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days = 31;

break;

default:

days = 30;

}

System.out.println(month "月份为" days "天");

}

}

错误示范

package com;

public class app4_4 {

public static void main(String[] args)throws Exception

{

int days;int month;

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

month=(char)System.in.read();

switch(month) {

case 2:

days = 28;

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days = 31;

break;

default:

days = 30;

}

System.out.println((char)month "月份为" days "天");

}

}

System.out.println((char)month "月份为" days "天");

month前面需要加char,不然会打印出ascll值。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页