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.
Three numbers
- 4
Locked
Comments (20)
- Popular
- New
- Old
You must be signed in to leave a comment
Kiran Kumar Alisam
4 April 2022, 02:31
if a==b then print c ; how to get the position ?
0
Vitalina
4 October 2020, 18:11
I used 3 if/else statements.
if (a == b) { system.out.println ("3");
etc..
+3
Joe M
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
0
joe
29 July 2020, 09:34
Verification does not work if using !=
0
Lucas Hoage
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.
0
Daniel
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. +5
Dyrits
3 July 2020, 07:55
Thank you.
+1
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.
+1
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 identical...to pass the last verification
+2
Talha
24 August 2019, 11:37
index = position?
+3
Marek Pasierbek Working at Nexus Polska
18 June 2020, 18:54
yes
+2
Andrei
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.
0
Tara Edwards
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.
+1
Nickolas Johnson
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.
0