I have a task that requires me to print out the following quantities:
I need to write a java program that can calculate:
1. the number of integers read in
2. the average value—which need not be an integer!
My final output should look like:
$ javac SimpleCalc
$ java SimpleCalc 3 4 6 8 1
5
8
4.4
7
I know i need to use a scanner class to read then as the user inputs then, i dont know how to make it display a count. I think that i can work this out, i can compute the average by adding up the numbers and divide the toal by the number of integers entered.
However its my first time writing a program, and this is doing my head in. Any help would be appreciated, ill even accept pseudocode if it helps me work out how to approach this.
Here you are supposed to use the arguments of the
mainfunction:Save this class in a file called
PrintArgs.javaand compile it usingjavac:Run the generated class file using
java:Now you know how to read input from the user. To convert a
Stringtoint, use theparseIntmethod of theIntegerclass:Now you know how to write your calculator program!