Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zpeukol2;
- import java.util.Arrays;
- import java.util.Scanner;
- public class ZpeUkol2 {
- public static void main(String[] args) {
- float soucetKlad = 0;
- float soucetZapor = 0;
- int nuly = 0;
- float zap = 0;
- float klad = 0;
- int pn[] = new int[7];
- Scanner sc = new Scanner(System.in, "Windows-1250");
- int pole[] = new int[7];
- for (int i = 0; i < 7; i++) {
- System.out.printf("Zadejte %d. číslo: ", i + 1);
- pole[i] = sc.nextInt();
- if (pole[i] == 0) {
- nuly++;
- pn[i] = 0;
- }
- if (pole[i] < 0) {
- soucetZapor = soucetZapor + pole[i];
- zap++;
- pn[i] = -1;
- }
- if (pole[i] > 0) {
- soucetKlad = soucetKlad + pole[i];
- klad++;
- pn[i] = 1;
- }
- }
- float prumK = soucetKlad / klad;
- float prumZ = soucetZapor / zap;
- System.out.println("Zadané pole je: ");
- for (int i = 0; i < pole.length; i++) {
- System.out.print(pole[i] + " ");
- }
- System.out.println("\nPočet nul: " + nuly);
- System.out.printf("Průměr z kladných čísel: %.1f\n", prumK);
- System.out.printf("Průměr z záporných čísel: %.1f\n", prumZ);
- System.out.println("Pole s nahrazenými prvky: ");
- for (int i = 0; i < pn.length; i++) {
- System.out.print(pn[i] + " ");
- System.out.println(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement