300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > JAVA获取当前学年学期 计算某年某月的学年学期

JAVA获取当前学年学期 计算某年某月的学年学期

时间:2019-11-06 08:31:23

相关推荐

JAVA获取当前学年学期 计算某年某月的学年学期

import java.util.Calendar;import java.util.Scanner;/*** @Author: Mencre* @Email: mencre@* @Date: /1/17/017 20:25* @Version 1.0*/public class Time {public static void main(String[] args) throws Exception {/* 如果在9、10、11、12、1月,为此学年第 2 学期,*其中在9、10、11、12月为 year 学年,1月为 year-1 学年。* 如果在2、3、4、5、6、7、8月,为此学年第 2 学期,*year-1学年。*///计算当前的学年学期Calendar cal = Calendar.getInstance();int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH )+1;int term = 1;if(month < 9)year = year - 1;if (month>2 && month<9)term = 2;elseterm = 1;System.out.println("现在是:" + year + " - " + (year + 1) + "学年," + term + "学期。");//计算输入的学年学期Scanner input = new Scanner(System.in);System.out.println("请输入年份:");year = input.nextInt();System.out.println("请输入月份:");month = input.nextInt();if(month < 9)year = year - 1;if (month>2 && month<9)term = 2;elseterm = 1;System.out.println("现在是:" + year + " - " + (year + 1) + "学年," + term + "学期。");}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。