View Single Post
Old Sep 29th, 2007, 1:40 PM   #4
Join Date: Sep 2007
Posts: 5
Rep Power: 0 truBlu1 is on a distinguished road
Thanks DaWei. I found it immediately when I started going through by hand. I was trying to access numbers[n-i] instead of numbers[(n-1)-i).

I have another question. Look at this segment of code. When my program outputs, it is concatenating the numbers as if they were strings. I get output like 1 + 13 = 113. Why does this happen? I've already fixed the problem by creating an integer variable and setting it equal to numbers[i]+numbers[(n-1)-i] but I'm still curious.

     for(int i = 0; i < n/2; i++)
      System.out.println(numbers[i] + " + " + numbers[(n-1)-i] + " = "
                                              + numbers[i]+numbers[(n-1)-i]);

I also added this to my first prompt:
    int n; //number of numbers to be read into the array
     n = keyboard.nextInt();
     if(n < 0)
       System.out.println("You must input a positive amount of numbers!");
    } while(n < 0);
truBlu1 is offline   Reply With Quote