任务是组织和显示与标记对应的用户输入.
例如,
姓名:奥斯卡马克:25,姓名:鲁宾马克:45,姓名:杰克马克:13
所以应该显示:
Rubin 45
Oscar 25
Jake 13
Run Code Online (Sandbox Code Playgroud)
当前代码仅显示名称和标记,但不按排列顺序显示.我怀疑它可能与做int
和String
,但我不能完全肯定.
private void btnEnterActionPerformed(java.awt.event.ActionEvent evt) {
for (int i = 0; i < 5; i++) {
ArrNames[i] = JOptionPane.showInputDialog("Enter a Name:");
ArrMarks[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter a mark:"));
}
}
private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {
for (int i = 0; i < 5 - 1; i++) {
for (int j = i +1; j < 5; j++) {
if (ArrNames[i].compareTo(ArrNames[j]); //>0 sorts in ascending order <0 sorts in …
Run Code Online (Sandbox Code Playgroud) private void EnterbuttonActionPerformed(java.awt.event.ActionEvent evt) {
if (Usernamefield.getText().equalsIgnoreCase("User"));
if (Passwordfield.getText().equalsIgnoreCase("420"));
{
JOptionPane.showMessageDialog(null, "Welcome, User!");
}
else
{
JOptionPane.showMessageDialog(null, "Wrong Username/Password!");
}
Run Code Online (Sandbox Code Playgroud)
它说如果没有if,else语句就无法工作,但是有明确的2 if语句.我想用Java创建一个简单的登录GUI.