• Post Reply Bookmark Topic Watch Topic
  • New Topic

Weird output using scanner  RSS feed

 
Marcos William
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Anybody know why my output is outputting weird characters using scanner?

I type "Welcome" and I get "InputReader@1f6670f".

Also, my assignment requires me to convert String to upper case, lower case and do a text count, would I be able do all of this stack together?


 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You are supposed to print what the input was, not what the Scanner was. userInput, not reader
As for what the “weird output” is, start reading here.
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, what sort of class is reader? getInput is not a method of this sort of Scanner.
 
Marcos William
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! I should had saw that. There will be more of that!

This is the scanner we used:



Thanks!
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InputReader is a utility class. Make all its members static, because they neither require any information from an instance nor pass any information to an instance.
Give it a private empty constructor, because you don't need any instances.
Initialise the Scanner in its declartion: private static final Scanner inScan = new Scanner...
Never close a Scanner pointing to System.in. If you don't know why, try it and then create a new Scanner pointing to System.in
Call all its methods on the class name InputReader.getInput()
You can create methods which will get the next int from the keyboard and not throw any Exceptions; I just happened to write about that earlier this morning.
 
Marcos William
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

If you search my posts for utility class and Scanner hasNextInt nextInt you will probably find enough information to build your own utility class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!