• Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting String to char  RSS feed

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to grab a letter from an array of numbers (char) and printout the remaining characters. So user is prompted to type in a character and the program prints out the remaining numbers left in the alphabet array. The problem is, when the scanner reads 'next' it seems to make the char a String. Any ideas to prevent or get around this is greatly appreciated.

>
 
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scanner's next() method returns a String. If you want to retrieve a character at a particular position, then you could use String's charAt() method.

Also, L is a char, which is a primitive, and does not have a equals() or any other method.
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Here is my code now:


I need a way to print the remaining alphabet after the letter chosen. Not sure how to do that.>
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One idea would be to save the position of the letter in the array found during search that you are already doing, then loop-through the array a second time, but this time starting after the position where the letter was found.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!