[SOLVED] Can I make a user input for a integer variable? Java

I'm trying to make a very simple calculator. I don't want to copy anyone's and it really will just be x + y =. I tried the scanner but it cant convert it to a int variable, does anyone know a way to do this?

2/12/2020 10:04:27 PM


5 Answers

New Answer


When you code figure out what the result will be on the right hand side of the = and then make sure you assign this to the corrent type. So you create a scanner object Scanner sc = new Scanner(System.in); This stores all the inputs so to find them you need to look inside the object and store it to the correct type. (runs code and inputs 33); int x = sc.nextInt(); First the right side of the code is computed which finds your integer input 33 and assigns this to x for you to use. https://code.sololearn.com/cf4S4418d9Z9/?ref=app


A simple way I’ve seen a lot of people do it is by asking for a number (Scanner.nextInt()), a Char (for the operation) and another number. If the Char was + print out both numbers added together


Blitzkriegster sorry for being harsh before, but there are way too many duplicates, and it's stressing. I hope you understand that I am just following the rules. But please take a look at the guidelines, to avoid this kind of answers next time. Thanks for understanding.


This question has already been asked, use the searchbar before posting next time please. https://www.sololearn.com/discuss/1171098/?ref=app https://www.sololearn.com/discuss/843362/?ref=app https://www.sololearn.com/discuss/1111946/?ref=app


Thank you so much Jax! Fixed the problem and helps a ton going forward!