作业:
给定一个大小为 n 的数组 nums ,返回其中的多数元素。
多数元素是指在数组中出现次数 大于 n/2 的元素。
[1,1,1,1,2,3,3]
//找给定的一个数组的大于数组长度一半的值
public static int getValue(int[] nums) {
if(nums == null || nums.length == 0) {
throw new IllegalArgumentException("argument error");
}
int flag = 0;
int returnValue = 0;
for (int num : nums) {
if(flag == 0) {
returnValue = num;
} else if(num == returnValue) {
flag++;
} else {
flag--;
}
}
return returnValue;
}
作业:综合案例(用户博客管理系统):
控制面板
用户注册
用户登录
保存用户信息
发表文章
保存模块
package entity;
public class Article {
private String title;
private String content;
private String digital;
private String author;
private String uploadTime;
public Article(String title, String content, String digital, String author, String uploadTime) {
this.title = title;
this.content = content;
this.digital = digital;
this.author = author;
this.uploadTime = uploadTime;
}
public Article() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getDigital() {
return digital;
}
public void setDigital(String digital) {
this.digital = digital;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getUploadTime() {
return uploadTime;
}
public void setUploadTime(String uploadTime) {
this.uploadTime = uploadTime;
}
}
package entity;
public class User {
public User(String userName, String passWord) {
this.userName = userName;
this.passWord = passWord;
}
public 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;
}
@Override
public boolean equals(Object obj) {
return this.equals(obj);
}
}
package blog;
import entity.Article;
import java.util.List;
public interface Blog {
void viewArticle(List<Article> articleList);
List<Article> publishArticle(List<Article> articleList);
}
package blog;
import entity.Article;
import java.text.SimpleDateFormat;
import java