rounding - Adding Decimal Places (3 Decimal Places) in Java -


I was wondering how to create avg at 3 decimal places in the following program: < / P>

  Public Class Baseball Clutter {Public Stable Zero Main (String AZ []) {Scanner MyScaner = New Scanner (System.); Bats at noon; Double Basehats; Double onbase; Double average; Double Onespresentage; System.out.println ("How many atbets did you have?"); AtBats = myScanner.nextDouble (); System.out.println ("How many base hits and homers were you?"); BaseHits = myScanner.nextDouble (); System.out.println ("How often do you get hits from the pitch or walking?"); OnBase = myScanner.nextDouble (); Avg = baseHits / atBats; OnBasePercentage = (baseHits + onBase) / atBats; System.out.println ("You Have Total" + BaseHit + "Base Hits for Season"); System.out.println ("You have total" atbats "on" Bat for the season "); System.out.println (" Your average for game or season: "+ average); System.out.println (" Your game or base percentage is for year: "+ on bus percentage"); Use it to format your output at 3 decimal places.}}    

< Div class = "post-text" itemprop = "text">

Output is integer.

  System.out.println ("Your average is for games or seasons:" + string Format ("% .3f", average));    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -