• Post Reply Bookmark Topic Watch Topic
  • New Topic

First java project and im stuck  RSS feed

 
andronik mkrtychev
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?
 
Junilu Lacar
Sheriff
Posts: 11165
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 11165
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Junilu Lacar
Sheriff
Posts: 11165
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll also need Integer.parseInt()

And Welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!