i need to compare these two arrays. one array in the lottotest class, method getdata gets the users numbers and stores them in an array. the nest in loto class, method gendata, generates 6 random numbers between 1-9. i need to then call both methods into the main method and compare them. please help

import javax.swing.JOptionPane;
import java.util.ArrayList;
class lottotest
{
  public static void main(String[]args)
  {
    final int numbers = 5;    
    double[] yourNumbers = new double[numbers];
    getdata(yourNumbers);
   
  }
  
  public static void blnResult(Double[] lotoNumbers)
  {
    getdata(double[] yourNumbers);
    boolean blnResult = ArrayList.equals(lotoNumbers, yourNumbers); 
      System.out.println("Are two int arrays equal ? : " + blnResult);
     
      }
  
    private static double getdata(double[] array) 
    {
      String input;
      
      for (int i = 0; i < array.length; i++)
      {
        input = JOptionPane.showInputDialog("Enter " +
                                 "your numbers 1-9 " + (i + 1) + ".");
        array[i] = Double.parseDouble(input);
        
      }
      return input;
    }
    }

.................................

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Loto 
{
  
  private static int gendata(double[] array)
  {
    ArrayList<Integer> lotoNumbers = new ArrayList<Integer>();
    for(int i = 1; i <= 8; i++)
      lotoNumbers.add(i);
    Random ran = new Random();
    
    for(int i = 0; i < 5; i++) 
    {
      int x = lotoNumbers.remove(ran.nextInt(lotoNumbers.size()));
      System.out.print(" " + x);
      
    }
    lottotest.blnResult(lotoNumbers);
  }
    
  }

Recommended Answers

All 2 Replies

what do you need to compare? that both arrays are equal? how many elements they have in common?

yeah i need to make the equal, because it is a lotto program so i am testing to find a winner. 6 elements in common. 1-9

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.