编写程序,使程序产生1到12的某个整数,然后输出相应的月份的天数。2

编写程序,使程序产生1到12的某个整数,然后输出相应的月份的天数。2月按28天算!

  Random r = new Random();
  int month = r.nextInt(12)+1;
  System.out.println("当前月份为"+month);
  switch (month) {
  case 1:case 3:case 5:case 7:case 8:case 10:case 12:
   System.out.println("本月有31天");
   break;
  case 2:
   System.out.println("本月有28天");
   break; 
  default:
   System.out.println("本月有30天");
   break;
  }

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-11-16
#includeintmain(){inty,m;scanf("%d%d",&y,&m);if(m==1orm==3orm==5orm==7orm==8orm==10orm==12)printf("31");if(m==4orm==6orm==9orm==11)printf("30");if(m==2){if((y%4==0&&y%100!=0)||y%400==0)printf("29");elseprintf("28");}while(1);return0;}追问

我看不懂啊……我才学

本回答被提问者采纳

...12之间的整数,利用Switch语句输出对应月份的天数.
public static void main(String[] args) { Scanner scan = new Scanner(System.in);int i = scan.nextInt();if (i<1&&i>12) { System.out.println("请重新输入月份");i = scan.nextInt();} switch(i){ case 1: System.out.println("本月有31天");break;case 2: System.out.p...

...1-12之间的整数,用switch语句输出对应月份的天数?
import java.util.Scanner;\\x0d\\x0a\\x0d\\x0apublic class QuestionOne {\\x0d\\x0a\\x0d\\x0aprivate static boolean start;\\x0d\\x0a\\x0d\\x0apublic static void main(String[] args) {\\x0d\\x0a\\x0d\\x0aboolean really=true;\\x0d\\x0aScanner sc=new Scanner(System.in);\\x0d...

假设月份为1-12之间的任意一个数据,输出各月份的天数。
public static void main(String[] args) { System.out.println("请输入月份(范围1-12,输入其他则退出):");Scanner sc = new Scanner(System.in);String month = sc.next();if(month.matches("\\\\d{1,2}") && Integer.parseInt(month) <= 12 && Integer.parseInt(month) != 0){ Da...

...若不符合条件则重新输入,利用switch语句输出对应月份的天数...
Scanner scn = new Scanner(System.in); \/\/ 要装JDK5.0以上才能支持 try { while (true) { System.out.print("请输入1-12中的一个数:");int input = scn.nextInt();switch (input) { case 1,3,5,7,8,10,12: \/\/大月31天 System.out.println("该月对应天数为:" + 31 + "天...

...1-12个数中的某个数,输出该数字对应月份的天数 C++求多种过程解法...
include <stdio.h>int main(){ int m, d[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; scanf("%d", &m); if (m >= 1 && m <= 12) printf("%d\\n", d[m-1]);}

...若不符合条件则重新输入 利用switch语句输出对应月份的天数...
public void fun(){ Scanner sc = new Scanner(System.in);try { int data= sc.nextInt();switch(data){ case 1: System.out.println("31 days");break;case 2: System.out.println("28 days");break;case 3: System.out.println("31 days");break;case 4: System.out.println("30 ...

编写JAVA程序,接受用户输入的1~12之间的整数,若不符合条件则重输入...
import java.io.*;public class Test { \/ param args \/ public static void main(String[] args) { \/\/ TODO Auto-generated method stub String inputStr=null;String input[]={"1","2","3","4","5","6","7","8","9","10","11","12"};String output[]={"31","28","31...

python打印某年某月有多少天(2023年最新整理)
ifnin[1,3,5,7,8,10,12]: return31 elifnin[4,6,9,11]: return30 elifnin[2]: return28 else: returnn,"isnotamonth" python输入月份判断天数怎么操作? 编写一个函数day_of_month(year,month) 编写程序输入年(year)、月(month),调用该函数,返回该年份该月的天数,输出返回的天数。 公历闰年的计算...

...1-12个数中的某个数,输出该数字对应月份的天数
cout<<"请输入月份"<<endl;cin>>month;cout<<month<<"月共有:";switch(month){ case 1:cout<<"31天"<<endl;break;case 2:cout<<"28天"<<endl;break;case 3:cout<<"31天"<<endl;break;case 4:cout<<"30天"<<endl;break;case 5:cout<<"31天"<<endl;break;case 6:cout<<"30...

...月份,并编写一个程序,根据用户输入的年份,输出该年各月的天数_百度...
int main (void){ enum month{January,February,March,April,May,June,July,August,September,October,November,December};char* name[]={"January","February","March","April","May","June","July","August","September","October","November","December"};int count[12] = {31,28,31,30...

相似回答