Java code to find Upper and Lower number of each element in an array -


i have array [22,30,32,36,40]

i want find nearest lower , upper value each element. ex. 22 , lower value 22 ani upper value 30. 30 , lower value 22 , upper 32. 32 ,lower value 30 , upper value 36. 36, lower 32 , upper 40.and last element 40 ,lower value 36 , upper 40. array becomes [ 22-30,22-32,30-36,32-40,36-40]

put items treemap. loop on items in original array , each of them lowerkey() in treemap predecessor , higherkey() successor. if either of them null mean it's lowest/highest , have take current element itself.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -