페이지 2 / 전체 3
2. 코드 #1
public static void main(String[] args) {
// int[] nums = { 1, 1, 1, 1 };
int[] nums = { 1, 2, 3, 4, 2, 5, 3, 1, 1, 2 };
int m = 5;
int result = 0;
for ( int i=0; i<nums.length; i++ ) {
int thisSum = 0;
for ( int j=i; j<nums.length; j++) {
thisSum += nums[j];
if ( thisSum == m ) {
result++;
break;
}
}
}
System.out.println("result="+result);
}
