Code practice

Write a method, checkRange, that takes in three integers, a value to check, the range high value and the range low value. It should return true if the value is within the high and low bounds inclusively.

public static boolean checkRange( int value, int highVal, int loVal)

{

return (value >= loVal && value <= highVal);

// There are other solutions using an if statement.

}

Write a method called isPrime that will accept an integer parameter and returns true if the integer is a prime number and false otherwise. (A prime number is divisible only by itself and 1.) You may disregard negative numbers and 0.

public static boolean isPrime(int number)

{

boolean result;

result = true;

for (int ii = 2; ii < number / 2; ii++)

{

if (number % ii == 0)

result = false;

}

return result;

}

Write a method called numberSquare which accepts an integer parameter, size, and displays a square of size, size, where each value is the same as the column number. So if the parameter were 5, the square would look like:

0 1 2 3 4

0 1 2 3 4

0 1 2 3 4

0 1 2 3 4

0 1 2 3 4

Use a tab (\t) between each value on a row and a new line at the end of each row.

public static void numberSquare(int size)

{

for (int row = 0; row < 5; row++)

{

for( int col = 0; col < 5; col++)

System.out.print(col + “\t”);

System.out.println();

}

}