calculate average java

Just some minor modification to your code will do (with some var renaming for clarity) :

double sum = 0; //average will have decimal point

for(int i=0; i < args.length; i++){
   //parse string to double, note that this might fail if you encounter a non-numeric string
   //Note that we could also do Integer.valueOf( args[i] ) but this is more flexible
   sum += Double.valueOf( args[i] ); 
}

double average = sum/args.length;

System.out.println(average );

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
math average java find average using variable in java get average method java find average method in java find average using method in java find average number of method in java find average number in java method find average number in java java how to calculate average get average java java get average code java how to find the average of results how to get average number in java how to compute the average num,ber in java how to take the average in java average om java how to calculate average using java average definition in java java get average java compute average java math average java calculate int average calculate mean java how to do average in java what to find average of integer in java 8 average of variable in java HOW TO FIND AVERAGE JAVA math.average java math.average in java average calculator in java code for average in java average number in java average java calculate the average in java calculating average java java find average java code for to find the average java function to find average how to get average in java java get a average how to calculate average in java java average method how to get the average in java java average finder average java program java calculate average how to find average in java get average value java average calculator java calculating average in java java average of numbers calculate average percentage in java calculate average in java average in java do an average in java how to find the average in java -Find the average in java how calculate average java java average how to calcualte average java calculate average java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source