Closest to 10

  • 4
Ten is extremely popular and attractive number. Everyone wants to be a ten. Or at least as close to it as possible. Two numbers are standing around wondering which of them is cooler. Answer: whichever is closer to ten. Let's write these numbers a displayClosestToTen method that will determine which of them is cooler.
You can't complete this task, because you're not signed in.
Comments (36)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Andrei Level 19, Romania
5 September 2020, 10:38
Hi people a few pointers if I may: 1. You need to do an operation with 10 and the variables; :) 2. You don't need to declare any variables, you can do the operation straight in the abs method while writing the if else statement 3. Remember that some operations with 10 might result in a negative answer so think about how this impacts the final result. 4. also use the else if statement. If you are not sure how to insert it, just quick google it! 5. Remember, you can do this! Just keep trying, write it down on the paper, how it should work, what results you should have! 6. Don't give up! Good luck!
Chris Level 9, Newark, United States
29 July 2020, 17:26
Hey guys, I have been going at this problem for over an hour and I am scratching my head about what I am doing wrong. Any pointers would be greatly appreciated!
Roman Level 41
31 July 2020, 05:57
Please use the Help section for questions relating to tasks.
Daniel Level 8, Vienna, Austria
5 May 2020, 14:01
Given that a double negative makes a positive, abs(int a) can be used to return absolute number. First substract the given numbers from ten and store them in a new variable (c and d for example).The result can also be a negative number. Use the if() statement to return a number for the giving conditions and don't forget to put the number inside the method so it's always positive. Good luck! Hint: if(abs(c) < abs(d) )...
Rebekah H Level 8, Gothenburg, Sweden
30 April 2020, 15:34
Hope no one minds if I brag a little (you should probably stop reading now if you do!), but I'm quite proud that I managed it on the first attempt with only 3 lines :]
Syed Huzaifa Level 7, Karachi, Pakistan
30 April 2020, 21:05
Bravo!
vishesh yadav Level 7, Mumbai, India
3 April 2020, 11:44
what am i missing? only last condition is not met.
Rebekah H Level 8, Gothenburg, Sweden
30 April 2020, 15:35
your output should be: 11 7
Syed Huzaifa Level 7, Karachi, Pakistan
30 April 2020, 21:04
depends on input. I don't want to give all. I know what u see over here that if both values are same then the pseudo code is giving out 0 its just a guide line not the solution. Lastly I mention it to reformat the code in the if else block format more over let me include something that this pseudo code is returning the value not displaying So, conclusively try to use the logic I just provide the logic not the solution of the code use it in different ways ;D And I saw you comment that u got it on your first attempt, Hats off for u. I don't get it on my first attempt but it let me read so many articles
Arun Level 16, Tirupati, India
6 February 2020, 10:50
Answer was correct, but didnt pass the test, why?
Roman Level 41
10 February 2020, 09:36
Please refer to Help section at our course.
HaeWon Chung Level 17, Boston, United States
16 January 2020, 04:46
My code doesn't implement the condition that a, b are equally close to 10 but I still pass the task. I think it's because the arguments didn't include the case where a equals b. I'm also a little bit confused with the last condition. Displaying 'either of them' means I should randomize the result? Or is it OK if I choose whatever number I want? For example, if I write a code something like
if (a = b)
System.out.println(a);
Does it meet the last condition?
Rebekah H Level 8, Gothenburg, Sweden
30 April 2020, 15:45
Basically if the program was fed 8 and 12, your output could be either 8 or 12, rather than displaying both or a text saying something like "both numbers are equally close to 10" So yes, the code you displayed should work :)
8 January 2020, 09:10
This one was very confusing, not difficult just very confusing: Tips for the new ones: EX: 9 and 11 are equally close to 10 so just display one of them without any text. To compare the distance between numbers you need to subtract 10 from them; EX: 7 and 14 ........ 7-10= -3 and 14-10=4 so 7 is more close to 10;
Nyerges Ferenc Level 23, Bükkábrány, Hungary
14 December 2019, 14:29
Well maybe its my English, but "either of them" can mean only one of them or both. A sample might be useful in "Conditions.tcs" for this situation.
Janusz Level 11, Radomsko, Poland
26 November 2019, 22:49
Both positive and negative values ​​a and b should be considered.