Results 1 to 2 of 2
  1. #1
    Brywiser is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default I need help writing an array backwards


    I need to type an array backwards. I am using jGrasp as my java code writer thing. This program needs to be interactive and asked the user for six decimal numbers positive or negative and the program needs to put the numbers in reverse order of how they where put in and say what the smallest, largest and average of the numbers were.



    Heres my code so far(does not even come close to what it is supposed to do), if you tell me to delete pretty much all of it that is fine)

    Java Code:
    import java.util.Scanner;
    public class DecimalArray1
    	public static void main(String[] args)
    		Scanner scan = new Scanner(;
    		double[] myList = new double[6];
    		System.out.println( "Enter a decimal number: ");
    		int index = 0;
    		while(index < myList.length)
    			myList[index] = scan.nextDouble();
    		System.out.println("\n\nYour values unsorted; ");
    		index = 0;
    		while(index < myList.length)
    Last edited by pbrockway2; 12-08-2011 at 12:48 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: I need help writing an array backwards

    Hi Brywiser, welcome to the forum!

    When you post code, use the "code" tags. Put [code] at the start of the code and [/code] at the end to preserve formatting.


    Break your problem into small steps and tackle them one at a time. Begin with printing the array in the reverse of the order in which it was entered. At the moment you put index equal to zero and then keep printing array elements while index<myList.length. To print them backwards start with index equal to the last index and keep printing elements while it is valid. Of course you have to decrement the index each time rather than incrementing it.

Similar Threads

  1. reading lines from URL and printing backwards
    By luxurymode in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2011, 08:18 AM
  2. Moving control backwards within loop in java
    By jharishabh7 in forum New To Java
    Replies: 16
    Last Post: 10-07-2010, 04:20 PM
  3. Writing and reading to/from a 2D array!
    By celebor in forum New To Java
    Replies: 11
    Last Post: 06-17-2010, 01:48 PM
  4. inputting and writing a file backwards
    By jigglywiggly in forum New To Java
    Replies: 0
    Last Post: 03-18-2009, 07:24 PM
  5. writing an array class
    By wardd85 in forum New To Java
    Replies: 5
    Last Post: 07-16-2008, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts