Professional Documents
Culture Documents
Dictation Scope - 2nd
Dictation Scope - 2nd
boolean isPrime(int n) {
if (n < 2)
return false;
for (int i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
Write a method getNextPrime that output the nearest prime number that is n or larger than n where n is input
by user
int getNextPrime(int n) {
int i = n;
while (!isPrime(i)) {
i++;
}
return i;
}
Write a method printArray that takes an array of integers as input and prints the array in the following
format:
[1, 2, 3, 4, 5]
1/3
Last Modified: 9/26/2023
Call the method printArray in the main method to print the following array:
[1, 2, 3, 4, 5]
Write a method that takes a 2D integer array and sum all the elements in the array, return the sum.
Call the method sum in the main method to sum the following array:
{{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15}}
Write a method sumRow that takes a 2D integer array and find the sum for each row of arrays, return the sum
of each row.
2/3
Last Modified: 9/26/2023
return result;
}
Call the method sumRow in the main method to sum the following array:
{{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15}}
3/3