Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2. import javax.swing.JOptionPane;
  3.  
  4.  
  5. public class StartClass {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner input = new Scanner(System.in);
  10. String value;
  11. double width, length, area;
  12. boolean repeat = false;
  13. do {
  14. try {
  15. value = JOptionPane.showInputDialog("Enter length rate: ");
  16. length = Double.parseDouble(value);
  17.  
  18. value = JOptionPane.showInputDialog("Enter width: ");
  19. width = Double.parseDouble(value);
  20.  
  21. area = length * width;
  22. JOptionPane.showMessageDialog(null, "Area is : " + area);
  23.  
  24. repeat = false;
  25. } catch (NumberFormatException e) {
  26. JOptionPane.showMessageDialog(null, "Error! Enter numeric value only!", "Data input Error", JOptionPane.ERROR_MESSAGE);
  27. repeat = true;
  28. }
  29. } while (repeat);
  30. input.close();
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement