嵌套 if 条件与同一范围内的代码行

问题描述 投票:0回答:1

// TRYING TO PUSH ELEMENT IN STACK WHILE APPENDING THE STRINGBUILDER

if(s.charAt(i)=='('){
    if(bracket.size()>0){
        sb.append(s.charAt(i));
    }
    bracket.push(s.charAt(i));
    // why this line of code is getting executed when size is greater than 1
}

if(s.charAt(i)=='('){
    if(bracket.size()>0){
        sb.append(s.charAt(i));
    }
    bracket.push(s.charAt(i)); 
    //this line of code should not execute when bracket size is greater than 1.
}

当满足 if 条件时,不应执行将元素推入堆栈的名为括号的行。

java stack
1个回答
0
投票

设置大于0就执行

© www.soinside.com 2019 - 2024. All rights reserved.