Ok, I have been trying to write a program that will read in a list of positive integers (including zero) and display some statistics regarding the integers.

This is what I have to do,

After you have placed all of the integers into an array, your program should perform the following tasks, in this order: 

1. Display the count of how many numbers were read 


2. Display the smallest number in the array 


3. Display the largest number in the array 


4. Display the median (the median is the integer that is stored in the middle position of the array) 


5. Display the average of all the numbers 


6. Allow the user to search the array for a specified value. 
First, ask the user to enter an integer to search for. 

Next, search the array to determine if the given integer is in the array.

If the integer is not found, display a message stating that the integer is not in the list. 

If the integer is found, then display the position number of where you found the integer. If the integer happens to be in the array more than once, then you only need to tell the first position number where you found it.

After performing the search, ask the user if he/she wants to search for more integers. Continue searching for numbers until the user answers "N".

And this is what I have so far,

import java.util.*;

public class ListStats {

//This is for the display part	
	public static void main(String[] args) {
		
		Scanner kbd = new Scanner(System.in);
		
		int numsList = 0;
	
		System.out.println("The amount of numbers read are: ");
		
		System.out.println("The smallest number found was: " + );
		
	}
		
//This is for getting the numbers from the user and putting thm in a array	
	public static int getNum(long[] num)
	{
		for (int i = 0; i < num.length; i++)
	{
			Scanner kbd = new Scanner(System.in);
			int nums;
			
			System.out.println("Enter a list of number ranging from 0 to 100 and put them from smallest to largest; ");			
			nums = kbd.nextInt();
			
			long []list = new long [nums];
			
		
	}
		return nums;
	}
	
//This is for finding the largest value	
	public static int findMax(int[] nums) 
	{
		int i = nums[0];
		
		for (int j = 1; j < nums.length; j++) 
		{
            if (nums[j] > i) 
            {
            	i = nums[j];
            }
        }

        return i;

	}

//This is for finding the smallest value
	public static int findMin(int[] nums) 
	{        
        
        int a = nums[0];

 
        for (int j = 1; j < nums.length; j++) 
        {
            if (nums[j] < a) 
            {
                a = nums[a];
            }
        }

        return a;
    }

//This is for finding the a specified value
	  public static int findVal(int[] nums, int val) 
	  {
	        
	        for (int b = 0; b < nums.length; b++) 
	        {
	            if (nums[b] == val) 
	            {
	                return b;
	            }
	        }
	        
	        return -1;
	    }

So my questions are, how do I put all the methods in the display part?

And how do I finish the 6th part?

And what am I doing wrong?

Thanks

For number 6, you can use the scanner again (so that you know what the user wants to search for). This will most likely involve a while loop

I have not yet compiled this but I think this works on your 6th problem...

import java.io.*;
public class prob6{
     public static void main(String [] args) throws Exception{
         InputStreamReader Reader = new  InputStreamReader(System.in);
         BufferedReader Buffer = new BufferedReader(Reader);
         int []  inArr = {1,2,3,4,5,6}
         boolean found = false;
         int search = 0;
         String ans = null;
         do{
            boolean = false;
            System.out.print("What number you want to search in the array? :");
            search = Integer.parseInt(Buffer.readLine());
            for(int i= 0; i<=5; i++){
              if(inArr[i] == search){
                  System.out.println("Number  "+search+ " was found at location " + i);
                  found = true;
                  break;
               }
             }
             if(found == false){
                  System.out.println("Number " + search + " was not found");
             }
         System.out.println("Try Again[Y/N]");
         ans=Buffer.readLine();
         }while(ans.equals("N")==false){
      
     }
}
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.