Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Help with chessboard location method  RSS feed

 
Greenhorn
Posts: 7
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a location method for a chess board, my approach:



When I create an object of the class, such as Location loc = new Location ("d8") and then print the location, it is always (0,0). (Shouldn't be, d8 would be 0,3)

Any ideas? Thanks for reading and thanks in advance for advice/help.
 
Saloon Keeper
Posts: 9213
177
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. Never use == for value comparison. St‌ring is a reference type, so == compares references, not values.

Anyway, you can do this without looping through arrays. char is an integral type that you can perform arithmetic on. All you need is String.charAt() and some maths.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!