1、程序流图必须将每个小判断都作为一个节点 而非网上大多数将一个复合if语句只作为一个节点而简化了流程图!

例如if ((A == B && B == C ) || (C == D && D == E)) 有四个判断 就会产生四个节点

下面进入正题:

本文不介绍soot及graphviz的安装方法

程序如下图所示:

public class Main {

    public static int cal(String[] args) {
        int A, B, C;
        Scanner SA = new Scanner(System.in);
        A = SA.nextInt();
        Scanner SB = new Scanner(System.in);
        B = SB.nextInt();
        Scanner SC = new Scanner(System.in);
        C = SC.nextInt();
        System.out.println("请输入三角形的三条边:");
        if ((A>0&&B>0&&C>0)&&((A+B)>C&&(A+C)>B&&(B+C)>A)) {
            if (A==B&&A==C) {
                System.out.println("该三角形是等边三角形!");
            } else {
                if ((A==B&&B!=C)||(B==C&&B!=A)||(A==C&&A!=B)) {
                    System.out.println("该三角形是等边三角形!");
                } else {
                    System.out.println("该三角形是普通三角形!");
                }
            }
        } else {
            System.out.println("ERROR!");
        }
        return 0;
    }
}

贴出soot的使用方法链接:https://github.com/Sable/soot/wiki/Introduction:-Soot-as-a-command-line-tool

1、首先将.java编译为.class

2、利用语句java -cp soot-3.0.0-jar-with-dependencies.jar soot.tools.CFGViewer -cp . -pp  Main 生成.dot文件

3、使用 dot -Tpng t.dot -o t.png生成控制流图

软件测试利用SOOT生成程序流图

有了程序执行的流图 我们是不是就可以很容易的手动画出控制流图了呢 :)

相关文章:

  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2021-12-26
  • 2021-05-30
  • 2022-02-27
  • 2021-12-02
相关资源
相似解决方案