Finding the maximum is an n-ary operation (an operation on n numbers) that returns the largest of several numbers. Never mind. We have no need for such definitions at the secret CodeGym center. We're here to learn how to write code. In this task, you need to use the keyboard to enter four numbers. Then determine the largest of them and display it on the screen.
Maximum of four numbers
- 4
Locked
Comments (23)
- Popular
- New
- Old
You must be signed in to leave a comment
BN CRISTIAN
19 February, 22:48
don't use another variable to store the max, just use conditionals and display it
0
gabrielgcb Backend Developer
4 October 2022, 15:07
My solution, very simple:
int max;
max = a > b ? a : b;
max = max > c ? max : c;
max = max > d ? max : d;
0
Anonymous #10771395 Backend Developer
13 August 2021, 06:52
why this solution is considered wrong? I've tried it several times and everything seems fine.
0
John Squirrels Website Admin at CodeGym
14 August 2021, 10:56
Please use the Help option within the task menu, if you are having issues with verification.
0
Jomar TayactacExpert
1 August 2021, 00:18
I used Arrays.sort() to get the max number.
0
Anonymous #10775689
26 July 2021, 15:52
How to create max method that gets 4 numbers and returns the maximum number?
This is a good discussion of Math.max.
0
coffeemess
21 June 2021, 19:50
used arrays.sort :)
+4
schipplock Backend Developer at n/a
4 July 2021, 18:03
lol :)
0
Seth Barker
26 January 2021, 20:27
The topic of Level 4 Lesson 6 should give some insight as to how to correct your code. It was so simple once I realized the most important word. "Equal to"
0
Khongpak Phupkdee
23 January 2021, 14:23
Thank the community help, because I forgot the negative value. If your result from your code It will be ok but you can't pass in Requirements 3 and 4. Try to change your input data from 8,9,5,8 to -8,-9,-5,-8, and check your result again! Good luck
0
Ryan Palmer
16 January 2021, 04:43
When using Intellij how do you input your own numbers? When I attempt to use "Run" and then type in the console I can only enter 1 number. When I push enter I receive the following message.
xception in thread "main" java.lang.NumberFormatException: For input string: "1 "
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at com.codegym.task.task04.task0419.Solution.main(Solution.java:13)
0
Alex Vypirailenko Java Developer at Toshiba Global Comme
16 January 2021, 17:10
Please contact Support with a screenshot of your task via support@codegym.cc.
0
Roman
18 January 2021, 06:52
Your input string is "1 " (spaces after the number are an error)
You should enter only the number.
0
Joe M
27 September 2020, 19:45
used Math.max and Buffered Reader!! woohoo!
0