/* 4. naloga */
public class Soda_vs_liha {
public static void main
(String[] args
) { // initaliziramo spremenljivke
int n = 0, stevilo;
int sodih = 0, soda = 0;
int lihih = 0, liha = 0;
// preveremo, koliko stevil zeli uporabnik prebrati
niz = javax.
swing.
JOptionPane.
showInputDialog("Koliko stevil zelis brati?");
// poskusimo pretvoriti v int, drugace zakljucimo program
try {
n =
Integer.
valueOf(niz
).
intValue();
}
// beremo stevila v zanki
for(int i = 1; i <= n; i++) {
niz = javax.
swing.
JOptionPane.
showInputDialog("Vpisi " + i +
". stevilo!");
try {
stevilo =
Integer.
valueOf(niz
).
intValue();
continue;
}
// ce je stevilo sodo, ga pristejemo k sodim
if(stevilo % 2 == 0) {
soda += stevilo;
sodih++;
} else if(stevilo % 2 == 1) {
liha += stevilo;
lihih++;
}
}
// izpisemo povprecje sodih stevil
System.
out.
println("Povprecje sodih stevil je: " + soda / sodih
);
// izpisemo povprecje lihih stevil
System.
out.
println("Povprecje lihih stevil je: " + liha / lihih
);
}
}