title: Counter Loop - Java
body: <p>Edit:  I have found a way to work with CompareTo to help with this problem, but for some reason I cannot get the count down to work.  </p>
  
  <p>It's a negative number that needs to get more negative to meet the requirements, but I am missing something here.  When I execute the down section it closes the program.  So to me this means that I have something messed up and the program isnt seeing the problem and closing.</p>
  
  <p>We are supposed to:</p>
  
  <blockquote>
    <p>Ask the user for an integer then ask the user if he/she wants to count
    up or down. Display a table of numbers where the first column contains
    the counter, the second column contains the counter plus 10, and the
    third column contains the counter plus 100. Make it so each number
    takes up 5 spaces total.</p>
    
    <p>If counting up, the first column should contain numbers 1 through the
    user input; If counting down, the first column should contain numbers
    -1 through the the negative of the user input;</p>
    
    <p>Do user input validation on the word "up" and "down". Allow for any
    case.</p>
  </blockquote>
  
  <pre><code>import java.util.Scanner;
  
  public class ps1 {
  
  public static void main(String[] args) {
      Scanner keyboard = new Scanner(System.in);
      //Comparision string already declared
      String up = "up";
      String down = "down";
  
      //initialize the counters sum
      int sum = 0;
  
      //ask the user for a number
      System.out.println("Enter an ending value");
      int num1 = keyboard.nextInt();
      keyboard.nextLine();
      System.out.println("Count up or down?");
      String input = keyboard.nextLine();
  
      while (input.equalsIgnoreCase(up) || input.equalsIgnoreCase(down)) {
          System.out.println("Count up or down?");
          input = keyboard.nextLine();
      }
  
      if (input.compareToIgnoreCase(up) == 0) {
          if (num1 &gt;= 0)
      for (int c = 1; c &lt;= num1; c++) {
              sum = sum + c;
              System.out.printf("%5d%5d%5d\n", c, c + 10, c + 100);
              else 
                  System.out.println("Up numbers must be positive");
  
      if (input.compareToIgnoreCase(down) == 0) {
              for (int c1 = -1; c1 &lt;= num1; c1--) {
                  sum = sum + c1;
                  System.out.printf("%5d%5d%5d\n", c1, c1 + 10, c1 + 100);
  
              }
          }
  
      }
  }
  }
  </code></pre>