• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Converting String to char

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

>
 
Marshal
Posts: 4810
602
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4810
602
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic