Results 1 to 2 of 2
  1. #1
    samwright92 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default 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());
    }
    }

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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.

Similar Threads

  1. Very new, and very lost
    By NoSwing in forum AWT / Swing
    Replies: 1
    Last Post: 03-09-2011, 04:14 AM
  2. Ok i am lost
    By jaisan72980 in forum New To Java
    Replies: 3
    Last Post: 01-17-2011, 05:20 AM
  3. I'm lost :(
    By leonardjr in forum New To Java
    Replies: 8
    Last Post: 03-03-2009, 05:18 AM
  4. So Lost
    By kandt in forum New To Java
    Replies: 5
    Last Post: 12-13-2008, 10:55 PM
  5. Lost my javadocs
    By orchid in forum Eclipse
    Replies: 3
    Last Post: 04-30-2008, 10:45 PM

Posting Permissions

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