报 cannot be resolved to a variable 这个错误

DྂOྂVྂEྂ 2021-05-12 10:11:17
import java.util.Scanner;

class User{
private String username;
private String password;
public String getUserName() {
return username;
}
public void setUserName(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
public class Dome {
Scanner input=new Scanner(System.in);
public static void main(String[] args) {
User[ ] users = new User[20 ];
for(int i=0;i<20;i++) {
users[i]=new User();
}
int count=0;
users[0].setUserName("张三");
users[0].setPassword("我就是张三");

Dome dome=new Dome();

// TODO Auto-generated method stub

dome.start();
}
public void start() {
System.out.println("----1---登录功能----");
System.out.println("----2---注册功能----");
System.out.println("----3---删除功能----");
System.out.println("----4---插入功能----");
System.out.println("----5---登录功能----");
System.out.println("----6---退出功能----");
while(true) {
System.out.println("请输入一个数字:");
switch (input.nextInt()) {
case 1:
this.login();
break;
case 2:
case 3:
case 4:
case 5:
case 6: System.exit(0);break;
default :System.out.println("请输入一个1-6的数字");this.start();
}
}
}
public void login() {
System.out.println("正在登录........");
System.out.print("输入用户名:");
String username=input.next();
System.out.print("请输入密码");
String password=input.next();
//遍历寻找用户名和密码是否存在,有则核对,无则退出
for (User user : users) { //这个users报错,我不知道怎们了
if (username.equals(user.getUserName()) && password.equals(user.getPassword())) {
System.out.println("验证通过");
System.out.println();
return;
}
else{
System.out.println("输入错误,请重新登录");
this.login();
}
}
}
}
...全文
728 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_39936465 2021-05-13
  • 打赏
  • 举报
回复
引用 楼主 DྂOྂVྂEྂ 的回复:
import java.util.Scanner; class User{ private String username; private String password; public String getUserName() { return username; } public void setUserName(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } public class Dome { Scanner input=new Scanner(System.in); public static void main(String[] args) { User[ ] users = new User[20 ]; for(int i=0;i<20;i++) { users[i]=new User(); } int count=0; users[0].setUserName("张三"); users[0].setPassword("我就是张三"); Dome dome=new Dome(); // TODO Auto-generated method stub dome.start(); } public void start() { System.out.println("----1---登录功能----"); System.out.println("----2---注册功能----"); System.out.println("----3---删除功能----"); System.out.println("----4---插入功能----"); System.out.println("----5---登录功能----"); System.out.println("----6---退出功能----"); while(true) { System.out.println("请输入一个数字:"); switch (input.nextInt()) { case 1: this.login(); break; case 2: case 3: case 4: case 5: case 6: System.exit(0);break; default :System.out.println("请输入一个1-6的数字");this.start(); } } } public void login() { System.out.println("正在登录........"); System.out.print("输入用户名:"); String username=input.next(); System.out.print("请输入密码"); String password=input.next(); //遍历寻找用户名和密码是否存在,有则核对,无则退出 for (User user : users) { //这个users报错,我不知道怎们了 if (username.equals(user.getUserName()) && password.equals(user.getPassword())) { System.out.println("验证通过"); System.out.println(); return; } else{ System.out.println("输入错误,请重新登录"); this.login(); } } } }
你设置了10个user,但是除了第一个user你设置了username和password,其他都没初始化这2个值。当然会报错。
顾染尘 2021-05-13
  • 打赏
  • 举报
回复
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧