Stern | Java program to print Brocot Sequence ; loop to create sequence ; adding sum of considered element and it 's precedent ; adding next considered element ; printing sequence . . ; Driver code ; adding first two element in the sequence
import java . io . * ; import java . util . * ; class GFG { static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) { for ( int i = 1 ; BrocotSequence . size ( ) < n ; i ++ ) { int considered_element = BrocotSequence . get ( i ) ; int precedent = BrocotSequence . get ( i - 1 ) ; BrocotSequence . add ( considered_element + precedent ) ; BrocotSequence . add ( considered_element ) ; } for ( int i = 0 ; i < 15 ; ++ i ) System . out . print ( BrocotSequence . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 15 ; Vector < Integer > BrocotSequence = new Vector < Integer > ( ) ; BrocotSequence . add ( 1 ) ; BrocotSequence . add ( 1 ) ; SternSequenceFunc ( BrocotSequence , n ) ; } }