title: I am generating a series of numbers delimited with space but I want to remove the space at end
body: <p>I am generating the series of numbers using for loop, delimited with space but I want to remove trailing space at last. Unable to use trim() for the output.</p>
  
  <pre><code> import java.util.*;
  public class Main {
      public static void main(String [] args){
          Scanner s = new Scanner(System.in);
          int str = s.nextInt();
  
      for(int i=1; i&lt;=str; i++) {
          System.out.printf("%d", i);
          System.out.print(" ");
      }
      }
  }
  </code></pre>
  
  <p>1 2 3 4 5(space here)</p>
  
  <p>but I want output without the space after 5.</p>