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(35)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
ChrisLevel 5 , Newark
29 July, 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!
RomanLevel 41
31 July, 05:57
Please use the Help section for questions relating to tasks.
5 May, 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 HLevel 7 , Gothenburg
30 April, 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 HuzaifaLevel 7 , Karachi
30 April, 21:05
Bravo!
vishesh yadavLevel 7 , Mumbai
3 April, 11:44
what am i missing? only last condition is not met.
Rebekah HLevel 7 , Gothenburg
30 April, 15:35
your output should be: 11 7
Syed HuzaifaLevel 7 , Karachi
30 April, 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
ArunLevel 15 , Tirupati
6 February, 10:50
Answer was correct, but didnt pass the test, why?
RomanLevel 41
10 February, 09:36
Please refer to Help section at our course.
HaeWon ChungLevel 17 , Boston
16 January, 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 HLevel 7 , Gothenburg
30 April, 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 :)
Mihai Daniel BoneLevel 9 , Bucharest
8 January, 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 FerencLevel 18 , Bükkábrány
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.
JanuszLevel 11 , Radomsko
26 November 2019, 22:49
Both positive and negative values ​​a and b should be considered.
SachinLevel 11 , Pune
22 November 2019, 14:34
use temp variable to hold the result of abs() checked with abs((a-10)) and then compare the both result and return the actual value based on result.