Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int positiveCount = 0;
- int positiveSum = 0;
- while (true) {
- System.out.println("Give numbers:");
- int number = Integer.valueOf(scanner.nextLine());
- if (number > 0) {
- positiveSum += number;
- positiveCount = positiveCount + 1;
- } else if (number < 0) {
- continue;
- } else {
- break;
- }
- }
- if (positiveCount == 0) {
- System.out.println("Cannot calculate the average");
- return;
- }
- double average = positiveSum / positiveCount;
- System.out.println("positive " + positiveSum);
- System.out.println("positive count " + positiveCount);
- System.out.println("positive average " + average);
- }
- }
Add Comment
Please, Sign In to add comment