Skip to content

Tag: arrays

Sort int[] array

I’m a bit confused on how to sort this array using the following conditions: int[] array = { 3, 15, 7, 11, 6, 4, 1, 8, 10, 13 }; The conditions are as follows: The largest integer is first The second-largest integer is last The third-largest integer should be second The pattern continues, leaving the sm…

How to convert lower triangular matrix into a vector?

I want to convert my triangular matrix into a vector. Let’s say I have 7×7 lower triangular matrix. Something like this: And I need to convert this matrix into a vector ignoring zeros. So, the result should be: I have already made a matrix by the following code: But I don’t really get how to …

Java array: Finding index always returns the highest

Part of one of our assignments was to generate an array and then find the sum, average, lowest, and highest values. I have all of those working, but our teacher has asked us instead to return the index of the highest and lowest values plus one (to coincide with a month number). The issue I’m running int…