Results 1 to 4 of 4
  1. #1
    SuperOnion is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Default Listing the alphabet (beginner)

    Hello.
    I am currently trying to do an assignment right now and I have no idea if I'm doing it right or not. The assignment is:
    Write a JAVA program that uses the ASCII codes and a for loop in a METHOD Alphabet() to display the alphabet in the following format:

    UPPERCASE LOWERCASE
    A a
    B b
    C c
    . .
    . .
    . .
    Z z


    This is all I have so far.
    Java Code:
    {
        public static void main( String args[] )
       {
    
                      char upper;
                      char lower; 
    
                          System.out.printf( "%s%20s\n", "UPPERCASE", "LOWERCASE");
                          for ( upper = 'A';  upper <= 'Z';  upper++ )
    
                      {
                          System.out.print(upper);
    System.out.println();
                      }
                      
                                     
    
    }
    }
    I don't even think this is correct but I can at least get the first row of uppercase letters down. Can someone help me set up the lowercase letters in the format that I was told to do? Oh and there is a big space between the two rows, just for some reason I can't set up the spaces while posting.
    Thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The Character class has a method called toLower() that might help. Try printing out Character.toLower(upper) and see what you get. You might even want to use printf from within the for loop to print both upper case, lower case and the space. Best of luck.

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

    Default Sorta...

    hhhmmm.. it's sorta a step in the right direction... but:
    • Your not using ASCII codes
    • There's no alphabet() method

    So you have some studying to do:

    • Here's a link to an ASCII table:

    Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
    • Here's a link to how to define a method in Java:

    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

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

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Easily you can do this.

    Java Code:
            for(int i =0; i < 128; i++) {
                if(Character.isLowerCase((char)i)) {
                    System.out.println("value: " + i + " character: " + (char)i);
                }
                if(Character.isUpperCase((char)i)) {
                    System.out.println("value: " + i + " character: " + (char)i);
                }
            }

Similar Threads

  1. Listing Logical Drives
    By Juggler in forum New To Java
    Replies: 3
    Last Post: 08-10-2008, 07:08 AM
  2. Listing all threads and threadgroups in the VM
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:36 PM
  3. Listing tables of a database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-12-2008, 09:30 AM
  4. Listing subdirectories/files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 07:19 AM
  5. Listing all available Locales
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 04:54 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
  •