have been confused by this easy problem,,,,

define a method that return the max of two numbers,always throw an error,but I have no idea about this error,......maybe you can help.me🌹 https://code.sololearn.com/cEuIiD7x60oJ/?ref=app

3/22/2019 12:01:04 AM


16 Answers

New Answer


Loving you💞🎈 There are few issues in your code. 1. you don't need two scanner instance to read two ints. Remove second scanner instance (bn) 2. you need to store values read in the variables int i = bv.nextInt() int j = bv.nextInt() 3. pass the values i,j to your maxc function currently what is happening is say you enter two nos 7 10 the statement System.out.println("your first enter:"+bv.nextInt()); will consume that input (7), you are left with 10. Next call to nextInt will consume 10 statement k=maxc(bv.nextInt(),bn.nextInt()); you are trying to read two new values, since there is nothing to read you get exception. If you trying to run your code sololearn then at input prompt enter both no at same time as sololearn doesn't support interactive sessions.


I just love coding and determined to be a better coder in the futher,now I am a student and learning programm


You atleast tried 👍 https://code.sololearn.com/cK7tp46AJLjz/?ref=app


Thank you so much🍀


JavaBobbo Happy to here that your program is working :)


~ swim ~ Its not my program and it wasnt me who needed helt but yes the code works hehe


You are welcome👍


JavaBobbo Is your program working now?


Your scanner read 4 numbers instead of 2. You should store the first two numbers and after printing them, put into the if and use always that values.


"I just love coding and determined to be a better coder in the futher,now I am a student and learning programm" I respect the fact that you gave it a shot, tried to figure it out, didn't give up, and then came here to ask for "help". You didn't ask for the fix (although you got it) like I've seen a few time. Getting the fix with out understanding why the fix fixes the issue would be useless... Unless, of course, the problem was for your homework or something. I've always said that the best way to learn is to mess up. Often than not, I end up learning more on the topic than just what's needed to solve the problem because I end up playing with the solution a few different ways and end up learning something else about it. Anyways, Good luck


the problem is that you the second scanner is throwing an exception since everything the user enters has already been „consumed“ by the first scanner... your second scanner instance doesnt receive the user input and therefor the call to next.int() causes an exception since there is no int in scanner 2


you need variables


wow coding is soooo hard


can somone pls tutor me?


so far so good


Loving you💞🎈 You already completed java course and you asking this type of questions it's funny