wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes ASCII code & loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ASCII code & loop" Watch "ASCII code & loop" New topic
Author

ASCII code & loop

Claire Pearce
Greenhorn

Joined: Jan 25, 2008
Posts: 4
i have been asked to program a code for some college work using the ascii code as a display on command prompt screen however, my tutor suggested using a 'for' loop?? hmmm puzzled nope glad your not but i can only figure it out as an 'if else' anyone got any suggestions? xx
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
I'm not sure I quite understand the requirement, but if you post the code you've written using if/else, I'm sure I (or someone else) will be able to point you in the right direction.
Remember to enclose the code in code tags (see the buttons below the window where you type your reply) as this makes it easier to read.


Joanne
Claire Pearce
Greenhorn

Joined: Jan 25, 2008
Posts: 4
Write a program which will print an ASCII values table (characters).

Method
A �for� loop should do the trick...

and you must include
Error conditions
If the last character is before the start character print an error message saying:
Error - last is before start
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
OK, requirement is now clear.

Reminder to all readers that we don't just want to post a full solution. That's not the JavaRanch way. And, to be fair, the original poster didn't request a solution - just guidance.

To specify the start and end, you will presumably want your program to accept two command-line arguments. These are the String array that gets passed to main(). You'll need to decide if you want to pass characters (e.g. A and Z) or codes (e.g. 65 and 91). Look at the java.lang.Integer class for how to convert a String to an integer. You may want to cast to char afterwards.

You will want an "if" (more than one, actually), to perform the error check that you are required to do.

You will indeed want a "for" loop, as the tutor hints. You'll need to loop from the first to the last chosen character. Within the loop, you'll want to print the numeric value and the character value of the loop variable.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
I would suggest you don't worry about the command line arguments to start with (unless you have already covered these in your course and understand them). Just try to print out the values 'A' to 'Z'. Give it a go and then post your code if you have any problems.
Once we have that working, it shouldn't be too difficult to work up to the actual requirements.

Here is the part of the Java tutorial that describes the for loop. There are a couple of examples of how to use it.
Claire Pearce
Greenhorn

Joined: Jan 25, 2008
Posts: 4
Thanks for your help i finally got my brain in gear and got a complete programme will post it later for your perusal many thanks for your help it was much appreciated guys xxx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ASCII code & loop
 
Similar Threads
Ascii cod problems..
Performing read/write to the file : how
operator cannot be applied to ints.
value of a character
Integer.valueOf