Results 1 to 4 of 4
Thread: Listing the alphabet (beginner)
- 12-22-2008, 02:50 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
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.
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.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(); } } }
Thanks in advance.
-
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.
- 12-22-2008, 03:22 AM #3
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-22-2008, 03:23 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
Listing Logical Drives
By Juggler in forum New To JavaReplies: 3Last Post: 08-10-2008, 07:08 AM -
Listing all threads and threadgroups in the VM
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:36 PM -
Listing tables of a database
By Java Tip in forum Java TipReplies: 0Last Post: 02-12-2008, 09:30 AM -
Listing subdirectories/files
By Java Tip in forum Java TipReplies: 0Last Post: 01-13-2008, 07:19 AM -
Listing all available Locales
By Java Tip in forum Java TipReplies: 0Last Post: 12-29-2007, 04:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks