Results 1 to 2 of 2
Thread: Cast int to char
- 02-05-2010, 06:06 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 56
- Rep Power
- 0
Cast int to char
Instead of printing a character value of count, all it prints is a blank line (or maybe ' '). I don't get why. Is that not the correct syntax for casting an int to a char??Java Code:public void updateGrid(ListStack<Position> stack) { LinearNode<Position> trav = stack.getTop(); int count = stack.size(); //go through stack, apply position numbers to the grid while(trav.getNext() != null) { char val = (char) (count); System.out.println(val); grid.getMap()[trav.getElement().getX()][trav.getElement().getY()] = val; trav = trav.getNext(); count--; } //end while }
- 02-05-2010, 06:27 AM #2
Member
- Join Date
- Nov 2007
- Location
- New Zealand
- Posts
- 36
- Rep Power
- 0
Your code does this...
// Get the length of this list and store it in count
// Convert the number count to a character and store in val
// Print the character stored in val
Are you sure this is what you want to accomplish?
Because lower character values are weird, some are just blanks.
For example:
(I don't see the goal of your code.)Java Code:class Test { public static void main(String[] args) { for (int i=0; i<92; i++) { char c = (char) i; System.out.println( i+ "[" +c+ "]" ); } } }
Similar Threads
-
Cannot cast JNLPAppletLauncher to itself
By kingofearth in forum Java AppletsReplies: 0Last Post: 01-19-2010, 07:37 PM -
Help with cast, equals and clone
By nellaf in forum New To JavaReplies: 1Last Post: 04-19-2009, 06:57 AM -
Cast From Image to String
By Deepa in forum New To JavaReplies: 4Last Post: 03-03-2009, 02:07 PM -
drawing char by char with Graphics
By diggitydoggz in forum New To JavaReplies: 5Last Post: 12-27-2008, 12:49 PM -
How can I cast Object as an int
By romina in forum New To JavaReplies: 1Last Post: 07-18-2007, 11:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks