• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

First java project and im stuck

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"If a player's playerID ends in 00 to 49, this person is on the “list 1”; however if the players ID ends in 50 to 99, this person is on the “list 2”."

I used the scanner tool to allow for player ID to be input but i dont understand how you would select the last two characters if the players ID is an 8-digits input. I was thinking switch statements or if else. Nothing has worked for me.
Any help?
 
Sheriff
Posts: 13510
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String.length() tells you how many characters a String has.

String.substr() returns a portion of a string.  The parameters you pass to substr() allows you to be very specific about which portion of the string to return.

Java uses a zero-based indexing system for strings. That is, the first character has an index of 0, the second character has index 1, etc. Therefore, the last character in a string has an index of length()-1
 
Junilu Lacar
Sheriff
Posts: 13510
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to the String API documentation for more details: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
 
Junilu Lacar
Sheriff
Posts: 13510
223
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll also need Integer.parseInt()

And Welcome to the Ranch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!