# Varied amounts of input data

We Are Going To Discuss About Varied amounts of input data. So lets Start this Java Article.

## Varied amounts of input data

1. Varied amounts of input data

`public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); int count = 0, max = 0, total = 0; int num = scnr.nextInt();`

2. Varied amounts of input data

`public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); int count = 0, max = 0, total = 0; int num = scnr.nextInt();`

## Solution 1

``````    public static void main(String[] args) throws IOException {
Scanner scnr = new Scanner(System.in);
int count = 0, max = 0, total = 0;

int num = scnr.nextInt();
while (num >= 0) {
count++;
total += num;
max = Math.max(max, num);
num = scnr.nextInt();
}

int avg = count == 0 ? 0 : total/count;
System.out.println(avg + " " + max);
}
``````

If you use while loop instead of do-while loop, you don’t have to count the negative number input anymore. And no, it’s not the most efficient way, but it’s a good start!

Original Author Of This Content

## Solution 2

``````import java.util.Scanner;

public class LabProgram {
public static void main(String[] args) {

Scanner scnr = new Scanner (System.in);
int userNum;
int maxNum = 0;
int totalSum = 0;
int averageNum;
int count = 0;

userNum = scnr.nextInt();

while (userNum >= 0) {

if (userNum > maxNum) {
maxNum = userNum;
}

totalSum += userNum;
++count;

userNum = scnr.nextInt();
}
averageNum = totalSum / count;

System.out.println("" + averageNum + " " + maxNum);
}
}

``````

Original Author Of This Content

## Solution 3

``````      int Num;
int max = 0;
int total = 0;
int average;
int count = 0;

Num = scnr.nextInt();

while (Num >= 0) {

if (Num > max) {
max = Num;
}

total += Num;
++count;

Num = scnr.nextInt();
}
average = total / count;

System.out.println("" + average + " " + max);
}
}
``````

Original Author Of This Content

## Conclusion 