+ 1

How to create waveform in java array

like the array elements goes in a way like the big number then small after that big then small.... according to the array order present.... for example - array is 4,2,5,6,1 then the output would be 4,2,6,1,5

21st Jan 2018, 7:44 PM
Aman Singh
Aman Singh - avatar
1 Answer
+ 1
Use a for-loop to iterate over all of your values, and in that for-loop, use a sin() function. If you want the function to be from 0 to 6, and all integers, then it'll look like round((1 + sin(x)) * 3). Firstly, the numbers (which are originally -1 to 1) are made positive by adding one (they are now 0 to 2) and then expanded to 0 to 6 by being multiplied. Since they need to be integers, they are rounded.
6th Aug 2018, 1:53 PM
Keto Z
Keto Z - avatar