ICSE Computer Methods Arrays Questions
ICSE Computer Methods Arrays Questions
Q: Write a method compareChar(char c1, char c2) that returns 0 if equal, -1 if c1<c2, 1 otherwise.
Code:
if(c1==c2) return 0;
else return 1;
2. Check if a + b + c = d
Code:
Code:
return x > y ? x : y;
return x > y ? x : y;
Code:
return true;
Logic: Each position selects the smallest element from unsorted part.
Code:
int idx = i;
arr[i] = arr[idx];
arr[idx] = temp;
}
CSE Computer Applications: User-Defined Methods & Arrays (PYQ + Toughest Questions)
Code:
int v = in.nextInt();
if(v % 2 == 0) even += v;
else odd += v;
Code:
arr[j + 1] = temp;
}
CSE Computer Applications: User-Defined Methods & Arrays (PYQ + Toughest Questions)
Logic: Use nested loops; outer for row, inner for columns.
Code:
int sum = 0;
sum += matrix[i][j];
Code:
for(int v : arr) {
Q: Find the contiguous subarray with the largest sum (Kadane's Algorithm).
Code:
return maxSoFar;