【简答题】使用switch语句编写程序:从键盘输入1-12任意月份,输出相对的英文单词,并计算第几季度!如果输入1-12之外数,输出“您输入的值非法!”(请上传执行结果图
这个程序会提示用户输入一个月份的数字(1-12),然后使用Switch语句根据输入的数字输出对应的英文月份名称。如果输入无效的数字,程序会显示"无效的月份"。 可以考虑以下思路: 了解问题:首先,明确题目要求,即编写一个程序,根据输入的月份数字,输出对应的英文月份名称。 考虑使用Switch语句:题目要求使用Switch语句,所以需...
include <stdio.h>int main(){ int m = 0; printf("请输入一个月份(1~12):"); scanf("%d",&m) switch(m) { case 1: printf("January\n"); break; case 2: printf("February\n"); break; case 3: printf("March\n"); break; case...
方法一:控制台输入月份 package com.liaojianya.chapter1; import java.util.Scanner; /** * This program demonstrates thw way of implements * display the number of days according to 12 months. * @author Hugh * 2016年7月19日 */ public class MonthAndDays { public static void main(String[] ar...
使用switch语句文本框输入一个月份,判断季节 int main(){int a;printf( 请输入月份:1-12 );scanf( %d ,&a);switch(a){case 1:case 2:case 3:printf( 春天\n );break;case 4:case 5:case 6:printf( 夏天\n );break;case 7:case 8:case 9:printf( 秋天\n );break;case 10:ca
switch(shu){ case 1:return January;case 2:return February;...case 12:return December;}
使用switch语句对输入的月份进行判断,并根据不同的月份设置对应的天数变量days。对于大月(1、3、5、7、8、10、12月),将days设置为31。对于小月(4、6、9、11月),将days设置为30。对于二月(2月),需要判断是否为闰年。如果是闰年(满足条件:能被4整除但不能被100整除,或者能被400整除),将days设置为29,否则将...
int i;switch (i)case 1:printf 一月的英文 break;case 2:printf 二月的英文 break;case 3:printf 三月的英文 break;...case 12:printf 12月的英文 break;这样的就可以,当然这个是不能执行的。只是告诉你格式,因为语法还没完整呢。只是类C语言。
switch建议判断固定值的时候用 if建议判断区间或范围的时候用 1.用switch实现键盘录入月份,输出对应的季节 importjava.util.Scanner;classHello2 {publicstaticvoidmain(String[] args) { Scanner sc=newScanner(System.in); System.out.println("请输入月份");intmonth =sc.nextInt();switch(month) ...
用switch语句判断月份,打印出当前月份所在的季节,vartoday=newDate();varabc=today.getMonth();switch(abc){case0:case1:case2:document.write("现在是春季");break;case3:...