+ 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
2 Respostas
+ 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;
}
}
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