What do I do if I want this code to be able to return any duplicated number even if it is not the maximum number. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What do I do if I want this code to be able to return any duplicated number even if it is not the maximum number.

see answer for code

3rd Mar 2017, 9:32 AM
Ricardo Chitagu
Ricardo Chitagu - avatar
2 Answers
+ 1
public class ArrayList { public static void main(String[] args) { double[] g = {1.9,2.9,5,5}; double max = getMax(g); System.out.println(max); int count=0; for(int i=0; i<g.length;i++) { if(g[i]==max) { count=count+1; } } if(count>=2) System .out.println ("1"); else System .out.println ("0"); } private static double getMax(double[] nums) { double max = nums[0]; for (int i = 1; i < nums.length; i++){ if (nums[i] > max) { max = nums[i]; } } return max; } }
3rd Mar 2017, 9:32 AM
Ricardo Chitagu
Ricardo Chitagu - avatar
0
we are not able to answer about code but we can help you with people who can do that. just check this could help you https://www.koachr.com/search?searchTerm=java
3rd Mar 2017, 9:39 AM
Koachr website
Koachr website - avatar