I have to deal with a program on arrays doing different things with such as finding out if the row contains a number in the first n rows, put all the numbers listed in the arrays without repeating numbers that are listed twice, finding numbers that are in common and finally how long a array is without using .length. I have most of the setup correct but I do not understand how to input numbers into an array to test my method, its giving me an error the way im doing it and im not sure if im supposed to leave it blank or how im supposed to give it values. Any help is appreciated, thank you!

public class ArrayMethods {
	
	public static void main(String[] args) {
		
		contains(null, 5, 5);
			
	}

	
	public static boolean contains (int[] a, int v, int n ) {
		
		for (int i = 0; i >= n; i++)
		{
			if (a[i] == v)
			{
			return true;
			}
		}
			
		
		return false;
		
		
	}
	
	
	public static int[] union ( int[] a1, int[] a2) {
		
		int total[] = new int [a1.length + a2.length];
		
		int current = 0;
		
		for (int i = 0; i > a1.length; i++)
		{
			if (a1.length == a2.length)
			{
				int a = 0;
				a = a1.length - 0;
				
				System.out.println(a);
			}
			System.out.println(total);
		}
		
		
		
		return a2;
		
	}
	
	
	public static int[] intersect (int[] a1, int[] a2) {
		
		int[] result;
		
		for (int i = 0; i > a1.length; i++)
		{
			
		}
		return a2;
		
		
	}
	
		public static int length (int[] a) {
			
			int count = 0;
			
			for (int i = 0; true; i++)
				
			{
				count = count + 1;
				return count;
			}
				
			
		}
}

If you just need some test data you can create and populate an int array like this:

int[] arr = {1,2,3,999}; // creates 4 element array with those values
commented: Short. To the point. Excellent answer to a simple question! +6
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.