Closest to 10

  • 4
  • Locked
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 (47)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Sharon de Jong
Level 7 , Netherlands
23 September 2022, 09:31
I finally got it done, but it took me several tries since it wasn't clear to me what the output should be. At first, I thought it should be a combination of the integer and a string like " is closer to ten". Then I removed the string but still got the error on what to do when both were equal. So I thought I should maybe display both of them. An example of the expected output would be beneficial in this situation.
Chloe
Level 13 , Alhambra, United States
11 October 2021, 06:39
what's wrong with my code? only last condition is not met.
Roman
Level 41
11 October 2021, 07:24
Please post your question with the attached solution in the section Help.
AlexDan Java Developer
26 June 2021, 17:24
I don't understand what's the problem here.
Jaime Padilla
Level 22 , Chandler, United States
11 April 2021, 07:08
I love how positive this course is and the words of encouragement, not only the writers give, but the fellow students as well.
ImDevin
Level 15 , Old Town, United States
28 March 2021, 23:52
Just felt like leaving a comment saying "Hey I'm doing the course." Anyone else currently working on these tasks? I see the last comment is from 2/4/21.
Jaime Padilla
Level 22 , Chandler, United States
11 April 2021, 07:09
Scottsdale?
Hoist
Level 22 , San Diego, United States
1 October 2021, 05:04
Cave Creek
Erick De Santiago
Level 6 , Dallas, United States
4 February 2021, 17:03
Not sure exactly what I am missing on my project. My code follows the following sequence: get abs for 10 - a; get abs for 10 - b; then using if statements i determine which value is closes to 10 (smaller number would be closes) when i run the program i get the expected output of 7 and 11. However, i still get an error on validations. "Be sure that the program works correctly with numbers that are equally close to 10" Any thoughts?
Erick De Santiago
Level 6 , Dallas, United States
4 February 2021, 17:11
NVM!! I read the comments below and realized that I needed to print any of the values (a or b) if they were both equally distant from 10. I was printing both. YAY!! this one felt good to complete
Andrei
Level 41
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 19 , 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 9 , 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!