title: How to remove trailing comma output?
body: <p>I'm asking the user to input an integer, and printing out even values within the range of that integer. Currently when I execute the code, it adds a comma after the final value (ex: &quot;2, 4, 6,&quot;). Is there a way that will remove the comma in the last number?</p>
  <p>Here's my code!</p>
  <pre><code>import java.util.Scanner;
  
  public class MyClass {
      public static void main(String args[]) {
          int integers;
          int sum = 0;
  
          System.out.println(&quot;Please input a positive integer: &quot;);
          Scanner myList = new Scanner(System.in);
          integers = myList.nextInt();
  
          if (integers &lt;= 0) {
              System.out.println(&quot;Invalid Input!!!&quot;);
          }
          else {
              System.out.println(&quot;Even number(s): &quot;);
  
              for (int i = 1; i &lt;= integers; i++) {
                  if (i % 2 == 0) {
                      System.out.print(i + &quot;, &quot;);
                      sum = sum + i;
                  }
              }
          }
      }
  }
  </code></pre>