0

So i would like to change this to show me the highest number not in what list the number is in. So basically i would like it to figure out the position of that number then print out what that number is.

import java.util.*;
public class TwoArrays
{
  public static void main (String args [] )
  {
    Random r = new Random();
    int rangeMin = 0;
    int rangeMax = 50;

    ArrayList<Double> arrayList1 = new ArrayList<Double>();
    ArrayList<Double> arrayList2 = new ArrayList<Double>();

    for (int i =0;i<5;i++) 
    {
      double randomValue = rangeMin + (rangeMax - rangeMin) * r.nextDouble();
      arrayList1.add(randomValue); 
    }

    for (int i =0;i<5;i++)  
    {
      double randomValue = rangeMin + (rangeMax - rangeMin) * r.nextDouble();
      arrayList2.add(randomValue ); 
    }


    Double maxInArray1 = Collections.max(arrayList1);
    Double maxInArray2 = Collections.max(arrayList2);

    if (maxInArray1>maxInArray2)
    {  
      System.out.println("first array have max");
    }
    else  if(maxInArray1<maxInArray2)
    {
      System.out.println("second array have max");
    }
    else
    {
      System.out.println("the max of second and first array is identical");
    }
  }
}
3
  • Are you trying to find the biggest number or which list the biggest number is in? Commented Sep 28, 2015 at 20:02
  • I am trying to figure out what the biggest number is between the two lists Commented Sep 28, 2015 at 20:05
  • 1
    Thanks CollinD for the organization Commented Sep 28, 2015 at 20:07

1 Answer 1

1

Try adding:

Double maxOfBoth = Math.max(maxInArray1, maxInArray2);

That will give you the biggest number between arrayList1 and arrayList2

Sign up to request clarification or add additional context in comments.

1 Comment

Straight after you create the maxInArray2 variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.