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
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.
Joined: Jan 25, 2008
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
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.
Joined: Aug 05, 2005
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.
Joined: Jan 25, 2008
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