让我们写下您的姓名和gpa,如果您的GPA是3或以上,则应该说它会接受您的工作,如果不是,那么它就不会。所以这一切似乎都在起作用,但它没有注册数字?不管我说的是什么号码都表示你不接受这份工作。我不清楚我必须放置什么代码以确保它知道输入是一个数字/它知道数字是否大于3.这是我的代码。
/^(?=.*\d)(?=.*[~!@#$%^&*)(_+:[}="`-])(?=.*[a-z])(?=.*[A-Z])[~!@#$%^&*)(+:[}="`\w-]{8,}$/
答案 0 :(得分:1)
你的问题是你没有比较输入而是你的常数,试试这个:
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//references to two objects: EditText and Button
final EditText inputName = (EditText) findViewById(R.id.nameET);
Button clickB = (Button) findViewById(R.id.showBTN);
final EditText inputGpa = (EditText) findViewById(gpaET);
final TextView outputa = (TextView) findViewById(messageTV);
//setting up a listener to the clickB
clickB.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//reading the user name input
String userName = inputName.getText().toString();
//This is where you get the numeric input
double n1 = Double.valueOf(inputGpa.getText().toString());
if(n1 >= 3) {
outputa.setText("Hello, " + userName + "With your current gpa, you will be considered for the job.");
}
else {
outputa.setText("Hello, " + userName + "With your current gpa, you will not be considered for the job, sorry.");
}
}
});
}
}