rounding - Adding Decimal Places (3 Decimal Places) in Java -
I was wondering how to create < Div class = "post-text" itemprop = "text"> Output is integer. 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.}}
System.out.println ("Your average is for games or seasons:" + string Format ("% .3f", average));
Comments
Post a Comment