Quick actions

cmd+k|ctrl+k

Navigation

Languages

Arrays - Getting Inputs from User

Snippet info

Language

Java

Visibility

public

Author

edmarfyelloww

Created

2020-03-13T11:41:36Z

Updated

2020-03-13T11:53:49Z

import java.util.Scanner;
//Unfinished -> Need  some  more functions  implementations 


class Main {
    
    
    public static Scanner scanner  = new Scanner(System.in);
    
    
    
    public static void main(String[] args) {
       
       int[] arrayIntegers = getIntegers(6);
       
       for(int i=0; i < arrayIntegers.length; i++)
       {
           System.out.println("Element " + i  + " Typed value was " + arrayIntegers[i]);
       }
      // System.out.println("Element is " + getAverage(arrayIntegers));
   
   
    }
    
    
    //Get Intigers  -> this function takes one parameter, this parameter is the size of Array
    //and we place the Integer Number as the array size -> int[] values =  new int[numb];
    //and we  say -> go throgh this array until his size and since the end of array  is not reached ask for a next Integer Input ;
    
    public static int[] getIntegers(int numb) 
    {
       System.out.println("Please enter "  + numb + " integer values on the array : \n");
        
        
        //The number now gonna define the array size
        int[] values =  new int[numb];
        
        
        //since the end of  array is not reached we ask for new input otherwise we break it.
        for(int i=0; i < values.length; i++)
        {
            values[i] = scanner.nextInt();
        }
        
        //Return the entire array  
        return values;
    }
    
    //Get the Average  -> Not defined yet!!!
    public static double getAverage(int[] array)
    {
        
        System.out.println("Working");
        
        
        return 0;
        
    }
    
    
    
}
INFO