|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectArrayProblems
public class ArrayProblems
ArrayProblems.java
CS 307
VERY IMPORTANT: For this assignment only, the only methods and classes from the
Java standard library you may use in your final solutions are:
1. All methods from the System class
2. All methods from the Math class
3. native arrays, including the arr.length field and creating and using new native arrays
Constructor Summary | |
---|---|
ArrayProblems()
|
Method Summary | |
---|---|
static int |
hammingDistance(int[] aList,
int[] bList)
Determine the Hamming distance between two arrays of ints. |
static boolean |
isPermutation(int[] listA,
int[] listB)
Determine if one array of ints is a permutation of another. |
static void |
main(String[] args)
|
static String |
maxSum(int[][] mat)
Determine which row or column in a matrix has the largest sum. |
static int[] |
minDifference(int[] nums)
Find the two values in an array of ints that have the smallest absolute difference. |
static int |
mostValuablePlot(int[][] city)
Given a 2D array of ints return the value of the most valuable contigous sub rectangle in the 2D array. |
static boolean |
queensAreSafe(char[][] board)
Determine if the chess board represented by board is a safe set up. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArrayProblems()
Method Detail |
---|
public static int hammingDistance(int[] aList, int[] bList)
aList
- != null, aList.length == bList.lengthbList
- != null, bList.length == aList.length
public static boolean isPermutation(int[] listA, int[] listB)
listA
- != nulllistB
- != null
public static int[] minDifference(int[] nums)
nums
- The array being searched.
nums != null, nums.length >= 2
public static String maxSum(int[][] mat)
pre: mat != null, mat.length > 0, mat is a rectangular matrix, mat[0].length > 0
post: determine which row or column of ints has the maximum sum in max.
If a row contains the maximum sum, return a string starting with "R" and
then the number of the row with no spaces. For example "R0" or "R12". If a
column contains the maximum sum, return a string starting with "C" and then
the number of the column with no spaces. For example "C0" or "C12".
If there is more than one row or column with the maximum sum
return rows over columns first, then smaller indices over
larger indices.
Thus if rows 3, 5, and 12, and columns 0 and 2 all contained
the same maximum sum the method would return "R3".
public static int mostValuablePlot(int[][] city)
pre: mat != null, mat.length > 0, mat[0].length > 0, mat is a rectangular matrix.
post: return the value of the most valuable contigous sub rectangle in city.
city
- The 2D array of ints representing the value of
each block in a portion of a city.
public static boolean queensAreSafe(char[][] board)
pre: board != null, board.length > 0, board is a square matrix.
(In other words all rows in board have board.length columns.),
all elements of board == 'q' or '.'. 'q's represent queens, '.'s
represent open spaces.
post: return true if the configuration of board is safe, that is no queen can attack any other queen on the board. false otherwise. the parameter board is not altered as a result of this method.
board
- the chessboard
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |