Three numbers

  • 4
  • Locked
Keyboard input, numeric comparisons, and screen output—4th-level CodeGym students hone these skills until they are automatic. Let's write a program where the user enters three numbers from the keyboard. Then we'll perform a comparison. If we find a number that differs from the other two, we'll display its ordinal number.
You can't complete this task, because you're not signed in.
Comments (20)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Kiran Kumar Alisam
Level 7 , Erie, USA
4 April 2022, 02:31
if a==b then print c ; how to get the position ?
Level 20 , Poland
4 October 2020, 18:11
I used 3 if/else statements. if (a == b) { system.out.println ("3"); etc..
Joe M
Level 47 , Owings Mills, United States
28 September 2020, 14:23
convert them to ints and choose the ordinal of the one that doesn't match. Still getting the weird println thing, being careful in IJ to get rid of old solutions seems to help
Level 27 , London, United Kingdom
29 July 2020, 09:34
Verification does not work if using !=
Lucas Hoage
Level 14 , Savannah, United States
25 May 2020, 20:39
This is doable with simple math, pemdas, comparing and if/else statements. No special functions are needed. Hint: Level 2 Lesson 8 (Minimum of 4 numbers) Level 4 Lesson 6 (Maximum of 4 numbers) and the other comparing lessons you learned will help you solve this.
Level 9 , Vienna, Austria
9 May 2020, 00:25
An ordinal number refers to a number that indicates the position or order of things or objects, such as first, second, third, fourth, and so on. ... SO: For the first case example: 4 is the first number. You'll have to display 1.
For the second case example: 3 is the third number. You'll have to display 3. Each with their number. REMEMBER, it's NOT the index because the index begins with 0.
I hope everything is clear now. :) Have fun.
Level 22
3 July 2020, 07:55
Thank you.
Josh Miller Full Stack Developer
18 February 2020, 19:06
The term "ordinal number" threw me for a little bit. Googled it and took me down a rabbit hole for a few minutes trying to figure out how to convert the number to the ordinal version. Figured out it's just talking about index position, basically, after a bit.
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
14 October 2019, 15:21
it says: One of the numbers is unique. The other two are identical. So I included that assumption...but should have allowed for none are pass the last verification
Level 5 , Lahore, Pakistan
24 August 2019, 11:37
index = position?
Marek Pasierbek Working at Nexus Polska
18 June 2020, 18:54
Level 41
22 September 2020, 08:11
you could use index of, but in the array where you get the index i recommend adding a 0 in the beginning. because indexof starts counting from 0 whereas you need the ordinal number which starts from 1.
Tara Edwards
Level 6 , United States
2 August 2019, 16:44
This one really annoyed me. I thought highlighting "index" meant I should find the actual index as in (1), but that code didn't work here because this is a FAKE index. That sets us up for future confusion where index actually starts with zero.
Nickolas Johnson
Level 8 , St. Louis, United States of America
4 March 2020, 16:01
I assumed the same thing. I've never even heard of an ordinal number. If there's any one thing that codegym assumes too much of it's that we have advanced math skills. I grew up in the rural USA. Math classes here are subpar.