Skip to content
Advertisement

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 smallest number in the middle.

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 convert that into a vector.

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 into is that trying

Method that scans array for most common word length, but sends error message if two different elements have the same length

I have a method that takes in an array (created by Scanner input in main) and sorts the array to find the most common words before printing the length of those words. However, I’m also trying to have an error message pop up if two different elements have the same length; this is where I’m having trouble getting started. Method:

Advertisement