我需要使用Homebrew版本的Python而不是Python的系统版本.我有一个干净的macOS Sierra安装(10.12.5).
我先安装自制软件然后更新~/.bash_profile使用nano ~/.bash_profile.然后我把它添加到文件中:
# Homebrew
export PATH=/usr/local/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
然后,我需要手动获取~/.bash_profile文件以确保已使用重新加载更改source ~/.bash_profile.
我安装了python brew install python并尝试使用链接brew linkapps python
输出是这样的:
Warning: Already linked: /usr/local/Cellar/python/2.7.13_1
To relink: brew unlink python && brew link python
Gautams-Air:~ gautam$ which python
/usr/bin/python
Gautams-Air:~ gautam$ python -V
Python 2.7.10
Gautams-Air:~ gautam$ brew linkapps python
Warning: brew linkapps has been deprecated and will eventually be removed!
Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using
either aliases or …Run Code Online (Sandbox Code Playgroud) 因此,如果我的值为 1234,则输出应为 4。
我写了以下代码,但不知道我做错了什么。这是一个应用程序,将两个数字相加。所以我有两个 EditTextfields。但是如果 EditTextfield 留空,应用程序就会崩溃。所以我想将 0 的值分配给一个已经留空的 EditTextfield,因为它(应该)的字符长度为 0。
那应该得到正确的结果:
例如,如果 EditTextfield "firstnumET" 的值为 5 并且 "secondnumET" 留空:
5 + 0 = 5
问题可能是
private int firstnum;
private int secondnum;
private int total;
EditText firstnumET;
EditText secondnumET;
TextView ansTV;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cal2_numbers);
firstnumET = (EditText) findViewById(R.id.edittxt1);
secondnumET = (EditText) findViewById(R.id.edittxt2);
ansTV = (TextView) findViewById(R.id.ans);
button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new ClickButton());
}
private class ClickButton implements Button.OnClickListener {
@Override
public void onClick(View …Run Code Online (Sandbox Code Playgroud)