예제

public static void main( String[] args ) {
if ( args.length > 3 ) {
System.out.println( "3 이상" ); //$NON-NLS-1$
if ( args[ 0 ].startsWith( "a" ) ) { //$NON-NLS-1$
System.out.println( "a로 시작" ); //$NON-NLS-1$
if ( args[ 1 ].endsWith( "z" ) ) { //$NON-NLS-1$
System.out.println( "z로 종료"); //$NON-NLS-1$
}
}
}
}

솔루션
조건을 변경하고 return 문을 추가하십시오.
Martin Fowler는 리팩토링에서 다음 솔루션에 대해 설명합니다.
  1. 가장 밖에 있는 if 문 조건의 앞뒤를 바꾸십시오.
  2. if 문 아래에 return 문을 추가하십시오.
  3. 더 이상 중첩된 if 문이 없을 때까지 이러한 단계를 반복하십시오.

public static void main( String[] args ) {
if ( args.length >= 3 ) {
return ;
}

System.out.println( "3 이상" ); //$NON-NLS-1$

if ( !args[ 0 ].startsWith( "a" ) ) { //$NON-NLS-1$
return ;
}

System.out.println( "a로 시작" ); //$NON-NLS-1$

if ( args[ 1 ].endsWith( "z" ) ) { //$NON-NLS-1$
System.out.println( "z로 종료" ); //$NON-NLS-1$
}

}