# I lost on how to connect the two

• 12-04-2012, 01:53 AM
samwright92
I lost on how to connect the two
I will have two public class

public class NumberInArray
{
int [] num;
public NumberInArray(int[] arr)
{
num = arr;
}
public int findMax()
{
int largest = num[0];
for(int x = 1; x < num.length; x++)
{
if(num[x] > largest)
largest = num[x];
}
return largest;
}
public int findMin()
{
int minimum = num[0];
for(int x = 1; x < num.length; x++)
{
if(num[x] < minimum)
minimum = num[x];
}
return minimum;
}
public double findMean()
{
double mean = 0;
int sum = 0;
for(int x = 0; x < num.length; x++) {
sum = sum + num[x];
}
mean = sum / num.length;
return mean;
}
}
import java.util.Scanner;
public class Test
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.println("How many numbers are in your array");
int num = input.nextInt();
System.out.println("Enter " + num + " Numerical Value(s) and press enter after each number: ");
int[] numbers = new int[num];
for(int i = 0; i < num; i++)
numbers[i] = input.nextInt();
System.out.println("All numbers accounted for...");
NumberInArray Wright = new NumberInArray(numbers);
System.out.println("The largest number in the array is: " + Wright.findMax());
System.out.println("The smallest number in the array is: " + Wright.findMin());
System.out.println("The mean of the array is: " + Wright.findMean());
}
}
• 12-04-2012, 03:02 AM