Beatty sequence | Java implementation of the above approach ; Function to print the first N terms of the Beatty sequence ; Driver code
import java . util . * ; class GFG { static void BeattySequence ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { int ans = ( int ) Math . floor ( i * Math . sqrt ( 2 ) ) ; System . out . print ( ans + " , ▁ " ) ; } } public static void main ( String args [ ] ) { int n = 5 ; BeattySequence ( n ) ; } }