Results 1 to 9 of 9
Thread: Displaying ASCII Characters
- 02-18-2013, 02:15 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 63
- Rep Power
- 0
Displaying ASCII Characters
I am attempting to display ASCII characters from ! to ~ , in decimal index from 33 to 126, 10 in each line
here is my progr
What am I doing wrong here?Java Code:import java.util.*; import java.lang.*; public class ASCIICharacterSet { public static void main(String[] args) { int DeciIndex = 33; final int NUMBER_PER_LINE = 10; int count = 0; while (count < NUMBER_PER_LINE ) { for( ; DeciIndex == 126 ; ++DeciIndex) { boolean goToNextCharc = true; if (goToNextCharc) { ++count; } if (count % NUMBER_PER_LINE == 0) { System.out.print( (char)DeciIndex ); } else { System.out.println( (char)DeciIndex + " " ); } } } } }
-
Re: Displaying ASCII Characters
What is wrong with your current code? Does it compile without error? Does it run without exception? Is it misbehaving in some way?
- 02-18-2013, 03:41 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 63
- Rep Power
- 0
Re: Displaying ASCII Characters
My bad, it complies but there is no output..
-
Re: Displaying ASCII Characters
Please translate what this for loop condition is supposed to do:
hint: I know what it's doing and why, and I want you to go through it and check each of the 3 sections to make sure you understand it too.Java Code:for( ; DeciIndex == 126 ; ++DeciIndex) {
- 02-18-2013, 05:45 AM #5
Member
- Join Date
- Feb 2013
- Posts
- 63
- Rep Power
- 0
Re: Displaying ASCII Characters
well,
for a for loop
for(initialization expression ; termination expression; increment/decrement statement)
that is the general syntax right.
So i did not put in an initialization expression as I already did so before the loop. Now the DeciIndex==126 expression is there because i want the loop to continue until the value of DeciIndex becomes 126 and finally the last expression adds one to the DeciIndex until it reaches 126.
Am i Correct?
Here is the more uptodate version of the code where I am getting all the ASCII characters but they are appearing vertically one after the other instead of 10 per line
Java Code:// ASCII characters from unicode 33 to 126 import java.util.*; import java.lang.*; public class ASCIICharacterSet { public static void main(String[] args) { int deciIndex; int count = 0; final int NUMBER_PER_LINE = 10; while (count < NUMBER_PER_LINE) { for( deciIndex = 33; deciIndex < 127 ; deciIndex++) { if( deciIndex <= 126 ) { boolean goToNextCharc = true; if (goToNextCharc) { ++count; } if (count % NUMBER_PER_LINE == 0) { System.out.print( (char)deciIndex ); } else System.out.println( (char)deciIndex + " " ); } } } } }Last edited by abi; 02-18-2013 at 06:15 AM.
- 02-18-2013, 06:22 AM #6
Member
- Join Date
- Feb 2013
- Posts
- 63
- Rep Power
- 0
Re: Displaying ASCII Characters
Well, I have solved all my problems and got the program running. Thanks Fubarable
-
Re: Displaying ASCII Characters
The middle part of the for loop is not a "termination" expression, it is a continuation expression. It must be true for the for loop to continue and the loop will terminate when its false. Is your expression ever true at the beginning, and if not, will the for loop ever stop? Answer: no and no.
- 02-20-2013, 04:35 AM #8
Member
- Join Date
- Feb 2013
- Posts
- 63
- Rep Power
- 0
Re: Displaying ASCII Characters
Thank You
-
Similar Threads
-
Non-ASCII Characters
By AJArmstron@aol.com in forum New To JavaReplies: 6Last Post: 05-06-2010, 10:16 PM -
Randomly generate a range of Ascii Characters
By Jamison5213 in forum New To JavaReplies: 2Last Post: 12-20-2009, 02:48 AM -
[SOLVED] special characters (ASCII) åäö
By AlejandroPe in forum New To JavaReplies: 8Last Post: 04-06-2009, 10:42 AM -
I need help with ascii characters
By Grandon in forum EclipseReplies: 17Last Post: 11-08-2008, 02:12 AM -
Printing ASCII values of characters
By Java Tip in forum Java TipReplies: 0Last Post: 01-21-2008, 04:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks