Hello guys

I have spend nearly whole day to find this answer ..
All i want to know , is what is an equivalent for this two simple to use functions from C .


In C this is very easy , and i believe that user friendly Java will make it piece of cake :)


Also i have discovered Scanner - thing thats fine , but what if i want to make like this :

user enter : 23 and 45 now i want to make it as a calculator , to choose what to do with numbers for that i need to get the +/*- ,
I can Scan the values but i cant scan the sign , and thats terrible :(
In c would be easy but here ??? any ideas what command should i use ?

Scanner's a good way to go. You can get the tokens one by one with next() and handle them one at a time, or you can get the whole mess as a String and parse it yourself - use nextLine() for that. Come to think of it, I don't recall whether next() on the command line will get tokens, or if it waits for the carriage return. I think it waits for the carriage return, so you'd be parsing the input yourself anyway.


EDIT: checked this. next() gets the first token of the line, after you hit the return. nextLine() gets the whole line after you hit return. Use nextLine and parse it yourself.


Whichever way you do it, you'll be getting input as a String or char, so you'll have to deal with that. Integer.parseInt() will do the conversion for you, so you don't have to write a conversion method, although you can do that if you like. It's about the same process if you do that.

If you really need to get character-by-character, I don't think the Scanner will do that for you. Maybe someone has a trick for that, I haven't come across that one yet.

Edited 5 Years Ago by jon.kiparsky: checked my facts

This article has been dead for over six months. Start a new discussion instead.