Learn Java for Beginners - 30 - Array Solution

preview_player
Показать описание
Java array and loop coding exercise solution

================================

The programming language Java is great to learn if you're a beginner.

Watch me solve the Java array and loop coding challenge.

Рекомендации по теме
Комментарии
Автор

me again with another question here's my solution still the wierd crash with closing input .Any ideas?









import java.util.Scanner;

public class arraytest extends Main {
    
    public static void main(String[] args){
        
        System.out.println("The average of these numbers is " +
    }// close main

    private static float getAverage(float[] nums) {
        // averages all the floats in the array
        
        float x = 0;
        for (int i = 0;i < nums.length;i++){
            
            x = x + nums[i];
        }//close forloop
       
        float y= x/nums.length;
        return y;
    }//close getAverage

    private static  float[] takeInput(int size) {
        // asks user for the values to average
        
        float[] nums = new float[size];
        Scanner input = new Scanner(System.in);
        
        for(int i = 0;i < size;i++){
            System.out.println("gimme floats!!");
            nums[i] = input.nextFloat();
            System.out.println("OM! NOM! NOM!!!");
        }//close forloop
        input.close();
        return nums;
        
    }//close takeInput

    private static int setArrSize() {
        // asks user for an int to use as the number of floats.
        Scanner input = new Scanner(System.in);
        System.out.println("How many numbers are we going to average?");
        int size = input.nextInt();
        //input.close();            WHY DOES THIS CRASH ME???    
        return size;
    }//close setArrSize

}//close Class

bigdirtygaming
join shbcf.ru