Created
March 1, 2012 20:01
-
-
Save anonymous/1952702 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class AddFloats{ | |
| public static void main(String[] args){ | |
| System.out.println("Please enter a positive floating point decimal to continue, or a negative number to halt"); | |
| Scanner standardIn = new Scanner(System.in); | |
| float sum = 0.0; | |
| float next_number = standardIn.nextFloat(); | |
| float average = 0.0; | |
| int numberOfEntries = 0; | |
| while(standardIn.hasNextFloat()){ | |
| if(next_number >=0 ){ | |
| numberOfEntries++; | |
| sum += next_number; | |
| }else{ break;} | |
| System.out.println("Please enter a positive floating point decimal to continue, or a negative number to halt"); | |
| } | |
| System.out.println("The average of the values you entered is: " + (float)Math.round((sum/numberOfEntries) * 10) / 10) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment