我想寫一個程序,從用戶(通過鍵盤)讀取一個整數,將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));
}
}
是我使用的代碼和:
Enter some text: 66
Your value + 100 is 10066
就是印在屏幕上。
這應該是'100 + number'。 –