I'm having trouble parsing a double from a string


Good morning,

I am creating a calculator bot for a project for class and I am having a bit of trouble parsing a double from a string from the user. The source code can be found here. As you can see, the error comes when I try and convert the string “num1” into a Double.

Thanks in advance!


Could this be the problem?

            double n1 = Double.parseDouble(num1);
            System.out.println(num1 + " and...");


I ran through the code with that change, but it didn’t seem to do anything. I would had an issue down the line with that. Thanks!


I don’t know Java beyond the very surface. Can numbers be concatenated with strings?

In the CC Java course there is basic integer based calculator to add, subtract, multiply, divide and return a modulo. Since I was hung up on the lengthy instruction sequence just for printing I wrote my own methods to simplify things. Don’t know if I’m going out on a limb, though. Works great. Here is a snippet from the Calculator class…

  public static void print (String str) {
  public static String ints (int num) {
    return String.format("%d", num);
  // methods

  // above this line
  public static void main (String[] args) {
    Calculator calc = new Calculator();
    print(ints(calc.add(5, 7)));

A subsequent method could be written to accomodate doubles.


i’m a new learner i got a sugesstion of a new job as a programmer in my home land i did some courses to my students in IT but it’s not as difficult as this career as a developer. i wish there is some one to help me hear. just to start simple codes inorder to hafe a chance to be selected for a training