Jump to content

[Java] Displaying an integer in place of a char/string


Recommended Posts

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?

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?)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.