用户输入数字不加在一起

jun*_*ior 1 java string int

我正在尝试编写一个从用户(通过键盘)读取整数的程序,向其添加100并显示结果.我所能做的就是让它们像2个字符串一样连接,而不是将数字加在一起.我无法理解为什么它不会添加它们.

import java.io.*;  
public class Program  { 
   public static void main(String[] args) throws IOException { 
      InputStreamReader isr = new InputStreamReader(System.in); 
      BufferedReader br = new BufferedReader(isr); 

      System.out.print("Enter some text: "); 
      String text = br.readLine();  
      int number = Integer.parseInt(text);

      System.out.println(" Your value + 100 is " + ( 100 + text));
     }
  }
Run Code Online (Sandbox Code Playgroud)

是我正在使用的代码:

Enter some text: 66
 Your value + 100 is 10066
Run Code Online (Sandbox Code Playgroud)

是什么印在屏幕上.

hex*_*ide 7

您正在添加错误的变量.请改用:

System.out.println(" Your value + 100 is " + ( 100 + number));
Run Code Online (Sandbox Code Playgroud)