34826

Reading Char using Scanner

Question:

I'm trying to write an educational, simple, calculator with no GUI. But I can't seem to know how to get the operation symbol from the user .. I need to get the Char provided by the user .. I'm new to Java, and I searched a lot .. but I couldn't find out how ..

Answer1:

Can you post some of the code you've got so far? I'm thinking you can use the Scanner class to grab the char entered by the user. I personally haven't used StdIn.readChar() before as fredley has suggested, but I'm quite new to Java too.

EDIT: Oops, I didn't read the question title:

This could work:

scanner.nextLine().charAt(0);

Answer2:

The scanner class in Java has no method defined to read character entered by user so you have to get the input in form of a string and then change it to a character by some suitable technique.

Recommend

  • Dynamic Programming - top-down vs bottom-up
  • Regex: match only outside parenthesis (so that the text isn't split within parenthesis)?
  • Chinese and Japanese character encoding issues when exporting HTML to PDF
  • WCF Service Application returns 404 using WebGet
  • Reduce Mono runtime size
  • Determining if a string has been entered with a leading single quote
  • Type mismatch: cannot convert from Connection to Connection
  • Inputting a number then reversing it
  • Drag and Drop for imageview not working
  • How can I get a specific line from a text file? [duplicate]
  • parsing numbers from a text file
  • CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9]
  • Regex for Specific Tag
  • How can we prepend rows to a react native list-view?
  • What's the purpose of QString?
  • how to find common suffix in java by using method
  • uniform generation of points on 3D box
  • SharedPreferences or SQLite Database?
  • Jackson Parser: ignore deserializing for type mismatch
  • Q promise. Difference between .when and .then
  • AES padding and writing the ciphertext to a disk file
  • Convert array of 8 bytes to signed long in C++
  • Why winpcap requires both .lib and .dll to run?
  • Linker errors when using intrinsic function via function pointer
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Memory offsets in inline assembly
  • Java static initializers and reflection
  • Turn off referential integrity in Derby? is it possible?
  • LevelDB C iterator
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize