9three Posted June 29, 2009 Share Posted June 29, 2009 Hey, I'm creating a simple Minesweeper game in Java for school. I'm having a small issue though. I don't know how to display an integer within a char variable. What I'm doing is checking the left, right, bottom and top for mines and if it's found increment the points for each mine. I'm using a bi dimensional array, Table[x ][y] (table is assigned as a char) and I'm printing it out. After adding all the points I want to display the points to that assigned coordinates (x, y). But I can't do Table[x ][y] == points as Table is searching for a character not an integer. I also tried doing Table[x ][y] = ' ' +points but that's a no go. Is there something I can do to display the points? Link to comment https://forums.phpfreaks.com/topic/164042-java-displaying-an-integer-in-place-of-a-charstring/ Share on other sites More sharing options...
corbin Posted June 29, 2009 Share Posted June 29, 2009 Well the number characters are 48-57: 0 = 48 1 = 49 .... 9 = 57 So as long as you're talking single digits, it's essentially (this is c++ code... you'll have to do the Java equivalent): char c = '5'; int num = ((int) c) - 48; (Or did I entirely misunderstand your question?) Link to comment https://forums.phpfreaks.com/topic/164042-java-displaying-an-integer-in-place-of-a-charstring/#findComment-865396 Share on other sites More sharing options...
9three Posted June 29, 2009 Author Share Posted June 29, 2009 I can't define the variable as the numbers will dynamically by the users total points. It could range from 0 to around 200 points. You get more points based on how many mines are around. Link to comment https://forums.phpfreaks.com/topic/164042-java-displaying-an-integer-in-place-of-a-charstring/#findComment-865524 Share on other sites More sharing options...
GingerRobot Posted July 5, 2009 Share Posted July 5, 2009 Perhaps i also misunderstood, but aren't you essentially looking to convert an integer to a string? http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#toString() Link to comment https://forums.phpfreaks.com/topic/164042-java-displaying-an-integer-in-place-of-a-charstring/#findComment-869108 Share on other sites More sharing options...
corbin Posted July 5, 2009 Share Posted July 5, 2009 I think he's trying to convert a string to an integer.... In which case, I'm not sure why I made it so complicated earlier.... Why not just do: Int i = new Int(str); Or what ever the Java equivalent is. Link to comment https://forums.phpfreaks.com/topic/164042-java-displaying-an-integer-in-place-of-a-charstring/#findComment-869301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.