相关疑难解决方法(0)

用户输入数字不加在一起

我正在尝试编写一个从用户(通过键盘)读取整数的程序,向其添加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)

是什么印在屏幕上.

java string int

1
推荐指数
1
解决办法
160
查看次数

标签 统计

int ×1

java ×1

string ×1