View Single Post
Old 11-10-2012, 11:52 AM   PM User | #1
coding-beginner
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
coding-beginner is an unknown quantity at this point
numbers programming

Hi,
I've only just started java and I am trying to to make a program so that when a any line of digits are added it prints the count N for the numbers (how many numbers are in the line), the minumum and maximum of the line of numbers, their sum, and the average of all the numbers. Each of these specifications has to be printed on a new line.
The program has a to be called NumberFor
eg.
>NumberFor 22.0 42.5 15.2 -2 6
4
-2
42.5
77.1
19.275

Currently I have:

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

double value = Double.parseDouble(args[0]);
double sum = 0.0;

//count N

// first value read initialized min and max
double max = StdIn.readDouble();
double min = max;

// read in the data, keep track of min and max
{
if (value > max) max = value;
if (value < min) min = value;
}

System.out.println(+ min);
System.out.println(+ max);

// sum of values
double N = Double.parseDouble(args[0]);
for (double i = 0.0; i < N; i++) {
sum += value;
}

System.out.println(+ sum);


//average
double cnt = 0;
while (!StdIn.isEmpty()){
sum += value;
cnt ++;
}
double average = sum / cnt;
System.out.println(+ average);
}

}

and the only output i can get to work is the max
coding-beginner is offline   Reply With Quote