0
Triangle Wave
I want pattern series code in java output is: 1 22 333 22 1 1 22 333 22 1 1 22 333 22 1 1 22 333 22 1 Input: 4 3 where: First line represents the value of N1 (frequencies of waves). Second line represents the value of N2 (amplitude of waves).
4 ответов
+ 1
need a for loop for N1 [1, N1] to print 4 times the wave.
Inside this loop a other for loop N2 [1, N2] to print 1,22,333 and 1 more for loop where you do the opposite 22,1.
And last thing you need to print 2 times the 2, 3 times the 3 etc, you need 1 more for loop
+ 1
other way to simplify it a bit, create a String array that contains the wave for example [1,22,333,4444,333,22,1] and print it N1 times
+ 1
Hannah the abs() function can give you a ramp up/down like that for one cycle.
i 3-abs(i)
--- -------
-2 1
-1 2
0 3
1 2
2 1
There is the core of your wave. Use an inner loop to print each number, as many times as the number itself. Use an outer loop to repeat the overall pattern.