by CodeChum Admin
Whole numbers are great, but I think we should also pay attention to decimal numbers, too.
So, how about we make a program that involves a lot of decimals?
Instructions:
Instructions
Input
Multiple lines containing float number on each.
1.1
1.2
1.3
1.4
-1.0
Output
A line containing a float number with two decimal places.
4.00
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
float number;
float sum=0;
do{
number=keyboard.nextFloat();
sum+=number;
}while(sum<100 && number>0);
System.out.printf("%.2f\n\n",sum);
keyboard.close();
}
}
Comments
Leave a comment