Results 1 to 5 of 5

Thread: Help please

  1. #1
    leonardjr is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default Help please

    This is my program
    Java Code:
    public class AlphaArray {
    
        public static void main(String[] args) {
        	char[] alphabet={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
        	System.out.println(alphabet);
        	for(int i=0; i<9; i++){
        		System.out.print(alphabet[i]);
        	}
        	for(int i=20; i<26; i++){
        		System.out.print(alphabet[i]);
        	}
        	System.out.println(alphabet[8]);
        	for(int i=25;i>=0;i--){
        		System.out.print(alphabet[i]);
        	}
    
        	System.out.println("This program was written by Justeena Leonard.");
        }
        
        
    }
    This is what is diplays

    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ABCDEFGHIJUVWXYZI
    ZYXWVUTSRQPONMLKJIHGFEDCBAThis program was written by


    This is what I need it to display
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ABCDEFGHIJ
    UVWXYZ
    I
    ZYXWVUTSRQP)NMLKJIHGFEDCBA
    This program was written by


    Can anyone help me?

  2. #2
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    Read the Sun tutorial about arrays:

    Arrays

    then try to analyse the output of your code..

  3. #3
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Your program is working almost the way you want it to... What is happening is that in your for loops you are using System.out.print... Which is what you want... This allows you to print the chars all together...

    Now what you need to do is do a System.out.println() after each loop... This will add a line and seperate everything the way you want it to...

    Then the last thing you want to do is in your first loop change it from i<9 to i<10... And you should get what you want...
    Who Cares... As Long As It Works...

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you should post what your program should do and what is required, not what you want output to look like. a working program by your description can be done in a single print statement.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    This is what I need it to display
    1)ABCDEFGHIJKLMNOPQRSTUVWXYZ
    2) ABCDEFGHIJ
    3) UVWXYZ
    4)I
    5)ZYXWVUTSRQP)NMLKJIHGFEDCBA
    6)This program was written by
    1) For this you want to printout the whole array:
    Java Code:
    for(int i=[COLOR="Blue"][B]0[/B][/COLOR]; i<[COLOR="blue"][B]alphabet.length[/B][/COLOR]; i++)
    and using System.out.print()
    2) For this one, you specify a certain number in the array:
    Java Code:
    for(int i=0; i<[COLOR="blue"][B]10[/B][/COLOR]; i++)
    also using System.out.print
    3) This needs a differnet starting point:
    Java Code:
    for(int i=[COLOR="blue"][B]20[/B][/COLOR]; i<[COLOR="blue"][B]alphabet.length[/B][/COLOR]; i++)
    4) no need to explain
    5) Start from the last element and work back:
    Java Code:
    for(int i=[B][COLOR="Blue"]alphabet.length[/COLOR][/B]; i[COLOR="blue"][B]>=0[/B][/COLOR]; i--)
    6) no need to explain

    To put on diffrent lines, place a System.out.println between them.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Posting Permissions

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