Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Blue Pelican Java- Array of Hope; char array for loops?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Blue Pelican Java- Array of Hope; char array for loops?

    The assignment is:

    This project called ArrayOfHope will consist of just one class, Tester, that in turn, has just one
    method, main. The main method will use two for-loops:
    The first loop will produce an integer count from 65 to 90 (notice these are the ASCII
    codes for characters AZ) and initialize the elements of the character array ch[ ] with
    the characters corresponding to the ASCII codes being generated by the loop. This will
    fill the ch[ ] array as follows: ch[0] = A, ch[1] = B, , ch[25] = Z.
    The second loop will print the 26 elements of the ch[ ] array with one comma followed
    by one space between adjacent characters as follows:
    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

    and so far I've got:



    public class Tester
    {
    public static void main (String args[])
    {
    char ch [] = {65, 66, 67, 68, 69, 70, 71, 72,73,74 ,75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90};

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

    for (int j = 0; j< ch.length; j++)
    {

    }

    }
    }


    I think I'm going about it in the wrong way, and I'm stuck. Can someone help me please?[


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,098
    My Mood
    Mellow
    Thanks
    244
    Thanked 754 Times in 740 Posts

    Default Re: Blue Pelican Java- Array of Hope; char array for loops?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers. Please correct your post.

    Also, describe why you think you're doing it the wrong way and why you think you're stuck. What results are you getting? What should be different? What do you think needs to be done to correct it? Ask specific questions.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Blue Pelican Java- Array of Hope; char array for loops?

    Quote Originally Posted by Draco579 View Post
    initialize the elements of the character array ch[ ] with the characters corresponding to the ASCII codes being generated by the loop
    Think: have you done this kind of initialization? You have done an initialization but with "cabled" values, not with calculated/derived values.

    Quote Originally Posted by Draco579 View Post
    The second loop will print the 26 elements of the ch[ ] array with one comma followed
    by one space between adjacent characters as follows:
    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
    You have done a loop to print the values, but the output is not that requested.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  4. #4
    Junior Member ZaneDarklace's Avatar
    Join Date
    Feb 2014
    Location
    Lawton, OK
    Posts
    15
    My Mood
    Lonely
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Blue Pelican Java- Array of Hope; char array for loops?

    I just finished this project. i used this code and it worked beautifully.

    ....
    Last edited by copeg; February 19th, 2014 at 11:27 AM. Reason: removed spoonfeeding
    Rock On

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,358
    Thanks
    182
    Thanked 834 Times in 777 Posts
    Blog Entries
    5

    Default Re: Blue Pelican Java- Array of Hope; char array for loops?

    @Zane, welcome to the forums. Please read Announcements - What's Wrong With My Code? (particularly point 7) and The Problem with Spoon-feeding.

  6. #6
    Junior Member ZaneDarklace's Avatar
    Join Date
    Feb 2014
    Location
    Lawton, OK
    Posts
    15
    My Mood
    Lonely
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Blue Pelican Java- Array of Hope; char array for loops?

    My apologies. I must have skipped over that. thank you
    Rock On

Similar Threads

  1. Char array to a String array with hex
    By fortune2k in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2014, 01:01 PM
  2. Help with java char Array
    By ashboi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 9th, 2012, 10:46 AM
  3. How do I compare between the array of char and array of words !!?
    By bady2050 in forum Collections and Generics
    Replies: 1
    Last Post: May 5th, 2012, 06:36 PM
  4. [SOLVED] Char Array Increment + 1
    By Nuggets in forum What's Wrong With My Code?
    Replies: 38
    Last Post: April 13th, 2012, 06:35 AM
  5. [SOLVED] Java program to sort arrays containing dates
    By scottyadam in forum Collections and Generics
    Replies: 1
    Last Post: March 9th, 2009, 07:08 PM

Tags for this Thread