Hi guys, I'm a real beginner at using Java, it's taking me almost all day to get what I've put together so far, but I'm having a real hard time getting it to print out the average, total, and count when I run my code and input my numbers, Here's what I have so far, any help on what to put in would be fantastic, as I'm really trying hard not to fail this course, and my professor has not been too helpful.

``````import java.util.*; // for class Scanner
public class Copy {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.println("Ready to copy numbers!\nPress \"a\" when you're finished.");
double num=0, count=0, total=0;
while(stdin.hasNextDouble())
{
num+=stdin.nextDouble();
total+=stdin.nextDouble();
count++;
}
System.out.println("Average:"+num/count);
System.out.println("Count:"+count);
System.out.println("Total:"+total+num);
}
}
``````

I know my code for finding the total is wrong, can anyone tell me what I need to so that it prints out the total?

Here's the code questions I was being asked:
Modify the program to print the
a. Count of numbers input - done
b. The total of the numbers input - NEED HELP
c. The average of the numbers input - done

``````import java.util.*; // for class Scanner
public class Copy {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
"Enter Control-Z when done!");
double num;
while(stdin.hasNext()) {
num = stdin.nextDouble();
System.out.printf("%.2f\n", num);
}
System.out.println("Goodbye!");
System.exit(0);
}
}
``````

Edited by minimee120

1
Contributor
1
2
Views
5 Years
Discussion Span
Last Post by minimee120

I THINK I'VE SOLVED IT, HERE'S WHAT I HAVE: If anyone would like to point out ways this can be done simpler I'm open to what you have to say !

``````import java.util.*; // for class Scanner
public class Copy {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.println("Ready to copy numbers!\nPress \"a\" when you're finished.");
double num=0, count=0, total=0;
while(stdin.hasNextDouble())
{
num+=stdin.nextDouble();

count++;
}
System.out.println("Average:"+num/count);
System.out.println("Count:"+count);
System.out.println("Total:"+num);
}
}
``````

Objective was to print out count of numbers input, total of numbers input, and average of numbers input

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.