lundi 5 août 2019

Is there anyway to check the count of nested control structures in a given code of java? such as, how many if conditions reside inside a while loop

I am given an assignment on java nested control structures. As a newbie I am unable to solve it by myself can you please help me? the assignment says that I have to measure the complexity of a given program by a user due to the number of nested control structures within a program. So I have to count the number of nested controllers in the given code. Is there any way to do that?

    String plus = "++";
    String minus = "--";

    int countplus = 0;
    int countminus = 0;

    for (int i = 0; i < words.length; i++) {
        if (words[i].equalsIgnoreCase(plus)) {
            System.out.println("found: ++");
            countplus = countplus + 1;

        }
        if (words[i].equalsIgnoreCase(minus)) {
            System.out.println("found: --");
            countminus = countminus + 1;
            if(countminus==10){
              System.out.println("count of minus signs are:"+countminus );
                 }

        }
    }

    jLabel11.setText("Count of  ++ : " + countplus);
    jLabel14.setText("Count of  -- : " + countminus);

If this is the given code, I should be able to get the output as:

Inside of the "for loop": there is only 1 "nested if" controllers

Aucun commentaire:

Enregistrer un commentaire