Home > Java > javaTutorial > body text

Detailed explanation of Java object-oriented array information processing examples

怪我咯
Release: 2017-07-02 10:34:44
Original
1490 people have browsed it

The following editor will bring you a brief discussion of array information processing in javaObject-oriented. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

Although it is a very simple thing, it should be of great help to some self-taught novices and newcomers who do not understand it deeply enough in the early stage. .

When I first learned object-oriented, I think many students were confused about this. Simple problems become complicated and unnecessary.

Then look down:

package cn.bdqn.test3;

import java.util.Scanner;

public class Test1 {
public static void main(String[] args) {
//创建两个管理员对象
Admin a1 = new Admin();
a1.name = "admin1";
a1.pwd = "111111";

Admin a2 = new Admin();
a2.name = "admin2";
a2.pwd = "222222";

//将管理员对象放入数组 (对象数组)
Admin[] admins = {a1,a2}; 
//修改管理员密码
Scanner input = new Scanner(System.in);
System.out.println("请输入用户名:");
String name = input.next();
System.out.println("请输入密码:");
String pwd = input.next();
int index = -1;
for(int i=0;i<admins.length;i++){
if(admins[i].name.equals(name) && admins[i].pwd.equals(pwd)){
index = i;
break;
}
}
if(index>=0){
System.out.println("登录成功!");
System.out.println("请输入新密码:");
String newPwd = input.next();
admins[index].pwd = newPwd;
System.out.println("修改密码成功,您的新密码为:"+admins[index].pwd);
}else{
System.out.println("用户名或密码错误!没有权限更新管理员信息");
}

}
}
Copy after login

Why do we need to reference objects? It’s because when there are a large number of objects that need to be If you input, you can omit many repeated operations by referencing the object.

Why do you need to create an array for object processing? For objects of the same class, if you need to check the error message, can we compare them one by one?

Understanding helps to learn new knowledge and deepen impressions. If you want to learn java well, you have to think more. I hope everyone will tell me if it is not well written. The reason why I write it is to communicate some experiences with

people and to support some of my own thoughts.

The above is the detailed content of Detailed explanation of Java object-oriented array information processing examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!