Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.text.NumberFormat;
- public class Dowhile2
- {
- public static void main(String args[])
- {
- NumberFormat formatter = NumberFormat.getNumberInstance();
- formatter.setMaximumFractionDigits(2);
- formatter.setMinimumFractionDigits(0);
- String input;
- Double one=0.0,total=0.0,ctr = 0.0;
- do{
- input = JOptionPane.showInputDialog("Enter one");
- if (input != null){
- if (input.equals(""))
- System.out.println("error");
- else {
- one = Double.parseDouble(input);
- total = one + total;
- ctr++;
- }
- }
- }while ( input != null);
- total = total/ctr;
- System.out.println(formatter.format(total) + " Is the avg");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement