Scanner sc = new Scanner( System.in ); int n = sc.nextInt(), x = 1; while( x < n ) { System.out.printf( "%d ", x ); x *= 3; }