Problems converting Integer to String

前端 未结 4 1800
Happy的楠姐
Happy的楠姐 2021-01-14 14:18

I am trying to add two numbers together from EditText fields. So far I have the code below that I believe converts the EditText field \'pos1_deg\' & \'pos2_deg\' into in

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-14 14:37

    When you concatanate a String to a non-String the result is a String.

    e.g.

    int deg1 = 5;
    int deg2 = 4;
    result.setText("" + deg1 + deg2): // passes in "45" (a String)
    result.setText("" + (deg1 + deg2)): // passes in "9" (a String)
    result.setText(deg1 + deg2); // passes in 9 (an int), compile error
    

提交回复
热议问题