ReverseArray

I have written a program that should read ten integers and display them in reverse order. I have an error in my method that I cannot find? Here is a copy of my source code. Any ideas or tips would be greatly appreciated. This is my second Java programming class. I am a student at CBU. Thanks.
package reversearray;
public class Main
public static void main(String[] args)
//Declare array and initialize
int[]reverseInt = {0,2,4,6,8,10,12,14,16};
//Call reverseIntegers method and pass array reverseInt
//create a separate place to store sorted list
int [] revList = reverseIntegers(reverseInt);
//print list of reversed integers
for (int x=0; x < reverseInt.length; x++)
System.out.println(revList[x]);
//reference to take given list from reverseInt array and return reverse list
//order from min to max to the revList array storage place
public static int [] reverseIntegers(int[]reverseInt)
int [] revisedList = new int[reverseInt.length];
for (int x=0; y=reverseInt.length-1; x<reverseInt.length; x++,y--)
revisedList[y]=reverseInt[x];
return revisedList;

I tried a space, ; and : and I still get the same error. I appreciate the help. I compared my code to one in the book and I can't find any difference? What does it's not a statement mean? I looked at some other discussions and best I can tell most developers point to missing braces { } ? I have to go to class now so I will post after I ask the professor. I will loose a couple of points but at least I will learn what it is. My professor tells me that is the best way to learn, to get frustrated and once you make the same error over and over you will finally get it and not make them anymore. Later.

Similar Messages

  • Problems with a while loop within a method... (please help so I can sleep)

    Crud, I keep getting the wrong outputs for the reverseArray. I keep getting "9 7 5 7 9" instead of "9 7 5 3 1". Can you guys figure it out? T.I.A (been trying to figure this prog out for quite some time now)
    * AWT Sample application
    * @author Weili Guan
    * @version 1999999999.2541a 04/02/26
    public class ArrayMethods{
       private static int counter, counter2, ndx, checker, sum, a, size, zero;
       private static int length;
       private static int [] output2, output3, reverse, array;
       private static double output;
       private static double dblsum, dblchecker, average;
       public static void main(String[] args) {
          //int
          //int [] reverse;
          System.out.println("Testing with array with the values [1,3,5,7,9]");
          size = 5;
          array = new int [size];
          reverse = new int [size];
          array[0] = 1;
          array[1] = 3;
          array[2] = 5;
          array[3] = 7;
          array[4] = 9;
          System.out.println("Testing with sumArray...");
          output = sumArray(array);
          System.out.println("Sum of the array: " + sum);
          System.out.println();
          System.out.println("Testing with countArray...");
          output = countArray(array);
          System.out.println("Sum of the elements : " + checker);
          System.out.println();
          System.out.println("Testing with averageArray...");
          output = averageArray(array);
          System.out.println("The average of the array : " + average);
          System.out.println();
          System.out.println("Testing with reverseArray...");
          output2 = reverseArray(array);
          output3 = reverseArray(reverse);
          //System.out.print(reverse[4]);
          System.out.print("The reverse of the array : ");
          for(ndx = 0; ndx < array.length; ndx++){
             System.out.print(reverse[ndx] + " ");
       private ArrayMethods(){
       public static int sumArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if (array[ndx] > 0){
                checker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                sum += array[ndx];
                ndx++;
             return sum;
          else{
             sum = 0;
             return sum;
        /*Computes the sum of the elements of an int array. A null input, or a
        zero-length array are summed to zero.
        Parameters:
            array - an array of ints to be summed.
        Returns:
            The sum of the elements.*/
       public static int countArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if(array[ndx] > 0 && array[ndx] != 0){
                checker++;
             counter++;
          return checker;
        /*Computes the count of elements in an int array. The count of a
        null reference is taken to be zero.
        Parameters:
            array - an array of ints to be counted.
        Returns:
            The count of the elements.*/
       public static double averageArray(int[] array){
          dblchecker = 0;
          ndx = 0;
          counter = 0;
          dblsum = 0;
          while(counter < array.length){
             if(array[ndx] > 0){
                dblchecker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                dblsum += array[ndx];
                ndx++;
             average = dblsum / dblchecker;
             return (int) average;
          else{
             average = 0;
             return average;
        /*Computes the average of the elements of an int array. A null input,
        or a zero-length array are averaged to zero.
        Parameters:
            array - an array of ints to be averaged.
        Returns:
            The average of the elements.*/
       public static int[] reverseArray(int[] array){
          ndx = 0;
          counter = 0;
          counter2 = 0;
          if(array.length == 0){
             array[0] = 0;
             return array;
          else{
                //reverse = array;
             while(ndx <= size - 1){
                   reverse[ndx] = array[4 - counter];
                   counter++;
                   ndx++;
                   System.out.print("H ");
          return reverse;
        /*Returns a new array with the same elements as the input array, but
        in reversed order. In the event the input is a null reference, a
        null reference is returned. In the event the input is a zero-length array,
        the same reference is returned, rather than a new one.
        Parameters:
            array - an array of ints to be reversed.
        Returns:
            A reference to the new array.*/
    }

    What was the original question? I thought it was
    getting the desired output, " 9 7 5 3 1."
    He didn't ask for improving the while loop or the
    reverseArray method, did he?
    By removing "output3 = reverseArray(reverse):," you
    get the desired output.Okay, cranky-pants. Your solution provides the OP with the desired output. However, it only addresses the symptom rather than the underlying problem. If you'd bother yourself to look at the overall design, you might see that hard-coding magic numbers and returning static arrays as the result of reversing an array passed as an argument probably isn't such a great idea. That's why I attempted to help by providing a complete, working example of a method that "reverses" an int[].
    Removing everything and providing "System.out.println("9 7 5 3 1");" gets him the desired output as well, but (like your solution) does nothing to address the logic problems inherent in the method itself and the class as a whole.

  • ToString() not working .

    This snippet is from my reverseTree class.
    public Object [] getReverse ()
    return reverseArray;
    This line is from my reverseTreeTest class.
    System.out.println(revTree.getReverse());
    If i overrided the toString() method in my reverseTree class, shouldnt this line invoke toString() and give me what i want. If I type use revTree.toString() I get the desired results. Any help??!?!?

    I must follow the following,
    /** class ReverseTree - copies the node contents of an ordered Binary Tree
    * into reverseArray, in reverse order.
    import java.util.*;
    public class ReverseTree {
         // Fields
         Object [ ] reverseArray;
         // Commands
         /** place contents of tree into reverseArray, in reverse order */
         public void reverse (TreeType tree);
         // Queries
         /** return the reverseArray */
         public Object [ ] getReverse ();
    My problem is that when I use getReverse() I get [Ljava.lang.Object;@1ded0fd. This is useless to me. How do I use this or get my objects out >.< I dont think I am supposed to have any loops(other than the one to build the tree) in my main class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Problem getting back to ethernet from wireless

    Hi.. I use my iBook all day at school wireless. In the evening at my dorm, when connected to ethernet, I find that my chat programs (msnmsgr, adium) and mail.app cant find any internet connection. Neither does irc work. But i can access internet thro

  • Oracle can only use 2GB on Windwos XP Server

    Hi all, Is the following statement true or false: "If the Oracle database runs on the Windows XP server (without access to the Datacenter version of Windows), the single-process architecture limits the Oracle database server to about 1.75GB of RAM in

  • Importing from CD to LR catalogue

    i have imported photos from a CD into my mac, to the spot on my drive where my LR files are stored, but I cannot get them to show up in LR?  , I try importing, i see them but they do not come into LR.  any suggestions?  thanks   joanlvh

  • Scanning mutliphoto​s

    I want to scan 4 photos at a time I have choosen that in the setting but each time it scans it just scans the whole glass 

  • ~HELP!~ WINXP WON'T BOOT ON 865PE NEO2-LS

    Hello, I just purchased the MSI 865PE NEO2-LS and an MSI FX5600. I wrote zeros to my hard drive and when I try to boot from the Windows XP CD or floppy this is the result: "Line 613 of the INF file i386   xtsetup.sif is invalid Setup cannot continue.