-2

I'm trying to compare two Array Ints.

This is what I have so far:

package array;

import java.util.Scanner;
import java.util.Arrays;

public class Array {

    public static void main(String[] args) {    

        Scanner input = new Scanner(System.in);            
        int [] lottery_number = new int[49];    
        int i;     
        int a = 0;
        for (i=0; i<lottery_number.length; i++){
            lottery_number[i]=i+1;
        }

        System.out.println("Please insert 6 numbers");     
        int [] Number = new int [6];    
        Number[0] = input.nextInt();
        Number[1] = input.nextInt();
        Number[2] = input.nextInt();
        Number[3] = input.nextInt();
        Number[4] = input.nextInt();     
        Number[5] = input.nextInt(); 
    }
}

I'm trying to compare the user input to certain Lottery_number array.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
  • 1
    There is no comparison anywhere in your code. What have you tried? Also, use proper java naming conventions in the future – user1231232141214124 Jan 07 '16 at 23:23
  • So, first off, its convention to have variables start with a lower case letter, so I would suggest making it number instead of Number. Just FYI Second: could you please clarify what you are comparing for? In what circumstance would the comparison be a success of a failure? – Jarrett Spiker Jan 07 '16 at 23:23
  • I can believe that you *want* to compare two arrays in some way. Your code shows no evidence of "trying to compare", however. – John Bollinger Jan 07 '16 at 23:23
  • 1
    You need 2 arrays: real numbers vs expected numbers. Then go to http://stackoverflow.com/questions/14897366/comparing-two-integer-arrays-in-java – ROMANIA_engineer Jan 07 '16 at 23:23
  • Well, is number some weird Wrapper class? Based on the comments not likely but aside from that, u enter 6 numbers, and what? You have 49 lottery #'s from 0-48, if they enter a number in that range you want to tell the user they won? – Mohamed Salad Jan 07 '16 at 23:26
  • What is the question? – Dima Jan 07 '16 at 23:37
  • 1
    @MohamedSalad if it were a wrapper class it wouldn't have `int` for a prefix but rather be `Number[] arrayName` – user1231232141214124 Jan 07 '16 at 23:48
  • Sorry it seems i have not explaned properly what my aim is to create a programme which compares certain arrays for example "Array 1,3,5,8,9,6" to the users 6 numbers. if they are correct then a if statement prints that they are correct or else it is uncorrect. – Uwayse Hussain Jan 08 '16 at 22:41

2 Answers2

0

I point out that I'm not sure of what you are asking, but it makes no sense to compare the lottery numbers array (all natural numbers from 1 to 50) with the player picks array (6 random numbers from 1 to 50. Using the static method

Arrays.equals(int[] array1, int[] array2)

will return whether the arguments are equals (same number of elements, same value) but eventually this is not the case. Sorry if I have completely misunderstood what you asked.

Massi A
  • 30
  • 5
-1

numberInCommon is a variable that says how many numbers the arrays have in common. I hope this is what you're looking for. You have to import java.util.Arrays

List lotteryNumbers = Arrays.asList(lottery_numbers);
int numbersInCommon = 0;
for(int i : Number){
    if(lotteryNumbers.contains(new Integer(i)))
        numbersInCommon++;
}

EDIT: You'll also need change
int [] lottery_number = new int[49]; to
Integer [] lottery_number = new Integer[49];

James McDowell
  • 2,668
  • 1
  • 14
  • 27