1.打印日历

1、输入年和月,打印对应月的日历,当前日通过星号标记出来 (借助于:Calendar)

public class Demonstrate {public static void main(String[] args) throws ParseException {Scanner scanner = new Scanner(System.in);System.out.println("请输入一个年份:");int year = scanner.nextInt();System.out.println("请输入一个月份:");int month = scanner.nextInt();System.out.println("日\t一\t二\t三\t四\t五\t六");if (month < 1 || month > 12) {System.out.println("输入有误!");} else {Calendar calendar = Calendar.getInstance();int day=calendar.get(Calendar.DAY_OF_MONTH);calendar.set(Calendar.YEAR,year);calendar.set(Calendar.MONTH,month-1);calendar.set(Calendar.DATE,1);//获取1号是星期几int week=calendar.get(Calendar.DAY_OF_WEEK);int count=0;//表示打印次数for(int i=1;i<week;i++){System.out.print("\t");count++;}for(int i=1;i<=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);i++){if(i==day){System.out.print("*\t");}else {System.out.print(i+"\t");}count++;if(count%7==0){System.out.println();}}}}
}

2、有一个字符串 “it is sunny tomorrow”

1.统计字符串中字母o出现的个数。

  1. 将字符串转换成一个字符串数组,要求每个数组元素都是一个有意义的英文单词,并打印输出。

    public class Demo2 {public static void main(String[] args) {String string = "it is sunny tomorrow";char[] chars = string.toCharArray();for (int i = 0; i < chars.length; i++) {if ('a' <= chars[i] && chars[i] <= 'z' || 'A' <= chars[i] && chars[i] <= 'Z') {System.out.print(chars[i]);}}System.out.println();String subString = "o";System.out.println("o出现的次数:");System.out.println(getSubCount(string, subString));}public static int getSubCount(String str, String substr) {int count = 0;int index = 0;while ((index = str.indexOf(substr, index)) != -1) {count++;index = index + substr.length();}return count;}
    }
    

3、编写一个程序,输出一个字符串中的大写英文字母数,小写 英文字母数以及非英文字母数.

public class Demo3 {public static void main(String[] args) {int supperCount=0;int lowerCount=0;int notCount=0;String string="It is sunny tomorrow";char[] chars = string.toCharArray();for (int i = 0; i < chars.length; i++) {if ('a' <= chars[i] && chars[i] <= 'z') {lowerCount++;}else if('A' <= chars[i] && chars[i] <= 'Z'){supperCount++;} else{notCount++;}}System.out.println("小写字母数:"+lowerCount);System.out.println("大小字母数:"+supperCount);System.out.println("非字母数:"+notCount);}
}

4.使用map集合求人数

有下列字符串:
销售:张三;财务:李四;销售:王五;财务:赵六;程序:mike;程序:jerry;美工:jackson;前端:green;前端:nick;程序:钱七;销售:alice
分析上述字符串然后统计每个职位总共多少人?
使用Map保存统计的结果,其中key:职位,value为该职位人数
然后分别输出各职位的名称(keySet),各职位人数(entrySet)

public class Exercise5 {public static void main(String[] args) {Map<String,Integer> map = new HashMap<>();String str="销售:张三;财务:李四;销售:王五;财务:赵六;程序:mike;程序:jerry;美工:jackson;前端:green;前端:nick;程序:钱七;销售:alice";String[] arr = str.split(";");String[] arr1;for (String s : arr) {System.out.println(s);arr1 = s.split(":");if(map.containsKey(arr1[0])){map.put(arr1[0],map.get(arr1[0])+1);}else {map.put(arr1[0],1);}}System.out.println(map);Set<String> strings = map.keySet();for (String string : strings) {System.out.println(string+""+map.get(string));}}
}

5.创建副本

7、要求用户输入一个文件名并使用File在当前目录下创建出来。
若该文件已经存在,则提示用户该文件已经存在。并创建该文件副本:
例如:用户输入"test.txt".若该文件已存在,提示用户存在后,创建名为:test_副本1.txt 的文件若该文件也存在了,则创建名为:test_副本2.txt 的文件,以此类推

public class Exercise7 {public static void main(String[] args) throws IOException {Scanner scanner = new Scanner(System.in);
//        System.out.println("请输入一个文件名:");
//        String path = scanner.next();
//        File file = new File(path);
//        if(!file.exists()){
//            file.createNewFile();
//        }System.out.println("请输入一个文件名:");String path1 = scanner.next();String[] arr = path1.split("\\.");File file1;int i = 1;while (true) {file1 = new File(arr[0] + "_副本" + i + "." + arr[1]);if (!file1.exists()) {System.out.println(path1 + "存在!");file1.createNewFile();System.out.println("副本创建成功!");break;}else {i++;}}scanner.close();}
}

Java 打印日历等五个经典程序题相关推荐

  1. c语言超长编程程序,全国青少年软件编程等级考试C语言经典程序题10道五

    全国青少年软件编程等级考试C语言经典程序题10道五 [程序41] 题目:学习static定义静态变量的用法 1.程序分析: 2.程序源代码: #include "stdio.h" ...

  2. n1 c语言程序,全国青少年软件编程等级考试C语言经典程序题10道七

    全国青少年软件编程等级考试C语言经典程序题10道七 程序61] 题目:打印出杨辉三角形(要求打印出10行如下图) 1.程序分析: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 1 ...

  3. c++经典编程题_全国青少年软件编程等级考试C语言经典程序题10道十

    全国青少年软件编程等级考试C语言经典程序题10道十 [程序91] 题目:时间函数举例1 1.程序分析: 2.程序源代码: #include "stdio.h" #include & ...

  4. Java日历打印_使用java 打印日历

    package hangshu; /* * 打印从1900年到2.year年的日历 */ import java.util.Scanner; public class Calender { publi ...

  5. java 打印日历

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  6. java 打印 日历 详细 注解_Java类库 LocalDate类的简单使用(一)之打印本月的日历...

    Java类库的设计者将保存时间与给时间点命名分开.所以标准Java类库分别包含了两个类:一个是用来表示时间点的Date类:另一个是用来表示日历表示法的LocalDate类.这里简单分析了LocalDa ...

  7. java 打印命令_Java 普通命令行程序main关掉 DEBUG 打印

    最近在写一个简单的java命令行程序,执行代码时,代码窗口出现了烦人的debug日志. 分析了一下,出现这种问题的原因是因为,maven项目的依赖包中传递依赖了一些日志框架,导致会出现日志内容的打印. ...

  8. java打印日历至Excel_2013日历打印_Excel2013,如何实现点击单元格就出现日历,操作者......

    2013年日历A4纸一张打印能 A4尺寸是210*297 竖版的话横着排三个 竖向排四个 看清应该完全没问题 如何设置outlook2013 的日历界面 运行outlook2013软件 outlook ...

  9. java if经典程序_java经典程序题15道(另附自己做的答案)

    [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一 对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1, ...

最新文章

  1. Python 函数知识汇总
  2. 虚拟化--012 多台虚拟机ping不通原因.
  3. KlayGE 4.0中Deferred Rendering的改进(五)完结篇:Post process
  4. OpenGL vs D3D
  5. Leetcode初级算法(链表篇)
  6. datable转xml
  7. boost::mpl::less相关的测试程序
  8. java中的md5加密_java中的MD5加密
  9. 在线rss阅读聚合器lilina-0.7安装笔记
  10. eclipse3.4+对的处理插件(附SVN插件安装实例)
  11. php相隔几分钟变换随机数,PHP怎么固定随机出号几分钟时间再变?
  12. 分布式日志收集系统Apache Flume的设计详细介绍
  13. 安装 Win10 Ubuntu 16.04 双系统以及 Ubuntu 配置深度学习环境记录
  14. hadoop本机运行 解决winutils.exe的问题
  15. 真北方向、坐标北向以及磁北向
  16. 矢量地图质量检查现状与需求分析
  17. 如何解决jupyter notebook更换浏览器时需要输入密码的问题
  18. Linux——进程管理(crontab实例傻瓜教程)
  19. 华为网络配置(DHCP)
  20. 关于html中的图片插入

热门文章

  1. 分享知识:个人授权委托书应当怎么写?
  2. 2017年1月10号
  3. 地理信息系统(GIS)系列——ArcGIS中的各种图层
  4. 生成HTTPS证书及使用
  5. 做一个让人相处舒服的人
  6. 利用FreeMarker实现网页到Word文档的生成
  7. 广西外国语学院计算机二级,广西外国语学院教务系统登录入口民办二本学小语种比较有前途...
  8. 痞子衡嵌入式:我入选了2021年度与非网(eefocus)星选创作者Top10
  9. vscode连接远程Linux服务器失败
  10. CentOS青龙面板安装