User input numbers not adding together

后端 未结 3 1389
轻奢々
轻奢々 2021-01-27 02:46

I\'m trying to write a program that reads an integer from the user (through the keyboard), adds 100 to it and displays the result. All I can do is get them to concatenate like 2

相关标签:
3条回答
  • 2021-01-27 03:08

    You are adding the wrong variable. Use this instead:

    System.out.println(" Your value + 100 is " + ( 100 + number));
    
    0 讨论(0)
  • 2021-01-27 03:21

    Text is the String, number an int, thus use:

    System.out.println(" Your value + 100 is " + ( 100 + number));
    

    For Strings + concatenates.

    0 讨论(0)
  • 2021-01-27 03:28
    int number = Integer.parseInt(text) + 100;
    
     System.out.println(" Your value + 100 is " + ( number));
    

    or

    System.out.println(" Your value + 100 is " + ( 100 + number));
    

    For a string "+" works to concatenate , i.e append the string together :)

    0 讨论(0)
提交回复
热议问题