使用Source Monitor检测Java代码的环复杂度

简介: 使用Source Monitor检测Java代码的环复杂度

Today I found a useful free software called “SourceMonitor” which can help to calculate and monitor the java code ( and other programming language like C++, C# etc ) complexity.

image.png

package test;
import java.util.ArrayList;
public class monthTool {
 static ArrayList<String> monthCollection = new ArrayList<String>();
 public static void main(String[] args) {
  monthTool tool = new monthTool();
  tool.printV1(1);
  tool.printV2(2);
  tool.printV1(0);
  tool.printV2(-1);
  tool.printV3(3);
  tool.printV3(13);
 }
 public monthTool(){
  monthCollection.add("Invalid");
  monthCollection.add("January");
  monthCollection.add("Febrary");
  monthCollection.add("March");
  monthCollection.add("April");
  monthCollection.add("May");
  monthCollection.add("June");
  monthCollection.add("July");
  monthCollection.add("August");
  monthCollection.add("September");
  monthCollection.add("October");
  monthCollection.add("November");
  monthCollection.add("December");
 }
 public void printV1(int month){
  System.out.println("Month is: " + getMonthNameV1(month));
 }
 public void printV2(int month){
  if( month >= 1 && month <= 12)
   System.out.println("Month is: " + getMonthNameV2(month));
  else
   System.out.println("Please specify a valid month");
 }
 public void printV3(int month) {
  System.out.println("Month is: " + getMonthNameV3(month));
 }
 public String getMonthNameV2(int month){
  if( month == 1)
   return "January";
  else if( month == 2)
   return "Febrary";
  else if( month == 3)
   return "March";
  else if( month == 4)
   return "April";
  else if( month == 5)
   return "May";
  else if( month == 6)
   return "June";
  else if( month == 7)
   return "July";
  else if( month == 8)
   return "August";
  else if( month == 9)
   return "September";
  else if( month == 10)
   return "October";
  else if( month == 11)
   return "November";
  else if( month == 12)
   return "December";
  else
   return "Invalid";
 }
 public String getMonthNameV1(int month){
  switch (month){
  case 1:
   return "January";
  case 2:
   return "Febrary";
  case 3:
   return "March";
  case 4:
   return "April";
  case 5:
   return "May";
  case 6:
   return "June";
  case 7:
   return "July";
  case 8:
   return "August";
  case 9:
   return "September";
  case 10:
   return "October";
  case 11:
   return "November";
  case 12:
   return "December";
  default:
   return "Invalid";
  }
 }
 public String getMonthNameV3(int month){
  try {
   return monthCollection.get(month);
  }
  catch (java.lang.IndexOutOfBoundsException e){
   return "Invalid";
  }
 }
}

image.pngimage.pngimage.pngimage.pngimage.png

相关文章
|
1天前
|
存储 安全 Java
掌握8条泛型规则,打造优雅通用的Java代码
掌握8条泛型规则,打造优雅通用的Java代码
掌握8条泛型规则,打造优雅通用的Java代码
|
1天前
|
Java 程序员 图形学
程序员教你用代码制作飞翔的小鸟--Java小游戏,正好拿去和给女神一起玩
《飞扬的小鸟》Java实现摘要:使用IntelliJ IDEA和JDK 16开发,包含小鸟类`Bird`,处理小鸟的位置、速度和碰撞检测。代码示例展示小鸟图像的加载、绘制与旋转。同时有`Music`类用于循环播放背景音乐。游戏运行时检查小鸟是否撞到地面、柱子或星星,并实现翅膀煽动效果。简单易懂,可直接复制使用。
|
2天前
|
数据库连接
java+ssm+vue代码视频学习讲解
java+ssm+vue代码视频学习讲解
5 0
|
2天前
|
SQL 缓存 算法
优化你的Java代码:性能调优技巧
优化你的Java代码:性能调优技巧
8 0
|
3天前
|
Java 编译器 程序员
Java一分钟之第一行Java代码:输出"Hello, World!"
【5月更文挑战第7天】本文引导初学者编写运行第一个Java程序——打印&quot;Hello, World!&quot;,介绍基本代码结构及常见问题。包括语法错误(如缺少分号、缩进不规范)、编译运行问题(忘记编译、运行错误)和环境配置问题(JDK未安装、环境变量未设置)。建议检查语法、熟悉编译运行流程并正确安装配置JDK。通过实战演练,从编写到运行,迈出Java编程第一步。
13 0
|
3天前
|
Java
接口在增强Java代码的灵活性方面起着关键作用
Java接口增强代码灵活性,实现多态性、解耦、多继承和扩展性。通过接口,类可隐藏实现细节,实现抽象化,促进模块化和维护性。接口定义方法,允许不同类实现,减少依赖,便于测试和修改。同时,接口提供多继承解决方案,使代码更具扩展性,易于添加新功能。
22 4
|
4天前
|
搜索推荐 Java Shell
8大Java排序方法(由简入繁),有代码详解和原理指导
8大Java排序方法(由简入繁),有代码详解和原理指导
22 0
|
1月前
|
Java
使用Java代码打印log日志
使用Java代码打印log日志
252 1
|
Java BI API
在Java代码中打日志需要注意什么?
日志是什么?日志是你在代码运行时打印出来的一些数据和记录,是快速排查问题的好帮手,是撕逼和甩锅的利器!
328 0
|
缓存 Java 网络架构
别在 Java 代码里乱打日志了,这才是正确的打日志姿势!
别在 Java 代码里乱打日志了,这才是正确的打日志姿势!
135 0