Java Saved Program: beautiful-dog

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Script" only */
class Script
{
	public static void main (String[] args)
	{
        int[] polje;
        int n, zbrojNeparnih = 0, brojacNeparnih = 0;
        float srvrNeparnih = 0;
        
        
	    Scanner s = new Scanner(System.in);
	    
	    do
	    {
	        System.out.println("Unesi broj elemenata polja!");
	        n = s.nextInt();
	    }
	    while( 2 > n || n > 100);
	    
	    polje = new int[n];
	    
	    for(int i = 0; i < n; i++)
	    {
	        System.out.println("Unesi " + (i + 1) + ". elemnt polja: ");
	        polje[i] = s.nextInt();
	    }
	    
	    for(int i = 0; i < polje.length; i++)
	    {
	        if((polje[i] % 2) == 0)
	        {
	            System.out.println("Parni: " + polje[i]);
	        }
	        else
	        {
	            zbrojNeparnih += polje[i];
	            brojacNeparnih++;
	        }
	    }
	        System.out.println("Zbroj neparnih brojeva: " + zbrojNeparnih + "\nSrednja vrijednost neparnih brojeva: " + (zbrojNeparnih/brojacNeparnih));
	}
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs