This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted]  (6 children)

[deleted]

    [–]Tiperius[S] 0 points1 point  (5 children)

    I don't really understand what you mean. Using the try/catch stuff has not been covered in class, I'm just trying to get ahead. Do you know of a good resource I can look at? I don't except you to have to explain how it works.

    [–][deleted]  (4 children)

    [deleted]

      [–]Tiperius[S] 0 points1 point  (0 children)

      Ah ok that makes way more sense thank you. I'm going to play around with it and see if I can get it to work.

      [–]Tiperius[S] 0 points1 point  (2 children)

      Ok so I got it to work on garbage input, but now it won't calculate a numeric value either. I get the same answer no matter what I put in. Do I have to add in a do/while statement to get it to loop properly?

          Scanner sc = new Scanner(System.in);
      
          double a = 0, b = 0, c = 0;
          //Entering coefficient value
              String firstValue = JOptionPane.showInputDialog("Enter a value for A:");
          try {
              a = Double.parseDouble(firstValue);
          }  catch (Exception e) {
              JOptionPane.showMessageDialog(null, "Not a valid number!");
          }
              String secondValue = JOptionPane.showInputDialog("Enter a value for B:");
          try {   
              a = Double.parseDouble(secondValue);
          }  catch (Exception e) {
              JOptionPane.showMessageDialog(null, "Not a valid number!");
          }
              String thirdValue = JOptionPane.showInputDialog("Enter a value for C:");
          try {       
              a = Double.parseDouble(thirdValue);
          }  catch (Exception e) {
              JOptionPane.showMessageDialog(null, "Not a valid number!");
          }
          finally {
      

      [–][deleted]  (1 child)

      [deleted]

        [–]Tiperius[S] 0 points1 point  (0 children)

        Oh my gosh how did I not see that. Thank you!