Hey guys Having a problem with my program i am writing this program out all in char format. it is suppose to out put the letters in order and then spit out the numbers in reverse. also the outputs that come out are in order and then off to the left where is it suppose to output the array number has a bunch of funky shapes. Please help. Thanks!

/**
* @(#)Week_nine_number_thiry_three.java
* Week_nine_number_thiry_three application
*
* @author 
* @version 1.00 2012/4/3
*/

public class Week_nine_number_thiry_three 

{

public static void main(String[] args) 
{
    char Letter [] = new char [9];
    Letter[0] = 'A';
    Letter[1] = 'B';
    Letter[2] = 'C';
    Letter[3] = 'D';
    Letter[4] = 'F';
    Letter[5] = 'G';
    Letter[6] = 'H';
    Letter[7] = 'I';
    Letter[8] = 'J';

    System.out.println("Forward");
    System.out.println("-------");

    for (char i = 0; i < Letter.length; i++)
    {
        System.out.println(" " + i + "  " + Letter[i]);
    }

    System.out.println("       ");
    System.out.println("=======");
    System.out.println("Reverse");
    System.out.println("-------");

    for (char r = Letter[9] - 1; r >= 0; r--)
    {

        System.out.println(" " + r + "  " + Letter[r]);
    }
  }
 }

Edited 4 Years Ago by Thermalnuke: miss spelling

well, you are making it a lot more diffult than you should. also, you should use an index as value for your loop, not the value of the elements.

for the first one, the easiest way is to use the enhanced for loop:

for ( char a: Letter) // btw, naming convention dictates lowercase letter, just a tip
System.out.print(a + " ");

the second one can be done in several ways, but if you use the chars as value for your index, that will only work if your chars are always in the correct order

for ( int i = Letter.length-1; i >= 0; i--)
System.out.print(Letter[i] + " ");

Letter[r]

this is wrong, since 'r' is not a valid index in your code.

Edited 4 Years Ago by stultuske

Thank you I got :

    public class Week_nine_number_thiry_three 

{

public static void main(String[] args) 
{
    String Letter [] = new String [9];
    Letter[0] = "A";
    Letter[1] = "B";
    Letter[2] = "C";
    Letter[3] = "D";
    Letter[4] = "F";
    Letter[5] = "G";
    Letter[6] = "H";
    Letter[7] = "I";
    Letter[8] = "J";

    System.out.println("Forward");
    System.out.println("-------");

    for (int i = 0; i < Letter.length; i++)
    {
        System.out.println(i + "  " + Letter[i]);
    }

    System.out.println("       ");
    System.out.println("=======");
    System.out.println("Reverse");
    System.out.println("-------");

    for (int r = Letter.length - 1; r >= 0; r--)
    {

        System.out.println(r + "  " +Letter[r] + " ");
    }
}

}

This question has already been answered. Start a new discussion instead.