# Thread: I lost on how to connect the two

1. Member Join Date
Nov 2012
Posts
3
Rep Power
0

## 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;
for(int x = 1; x < num.length; x++)
{
if(num[x] > largest)
largest = num[x];
}
return largest;
}
public int findMin()
{
int minimum = num;
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());
}
}  Reply With Quote

2. Senior Member Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
13

## Re: I lost on how to connect the two

What do you mean that you are lost? And please format you code using [code][/code] to make it readable.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•