作业:
给定一个大小为 n 的数组 nums ,返回其中的多数元素。
多数元素是指在数组中出现次数 大于 n/2 的元素。
[1,1,1,1,2,3,3]
public class Import {
public static void main(String[] args) {
int[] arr = {1, 1, 1, 1, 2, 3, 3};
System.out.println(howe(arr));
}
public static int howe(int[] nums) {
int left=0;
int right=1;
int count=1;
while (left<right&&right<nums.length){
if (nums[left]==nums[right]){
count++;
if (count> nums.length/2){
return nums[right];
}
}
left++;right++;
}
return 0;
}
}
作业:综合案例(用户博客管理系统):
public class user {
private String name;
private int age;
private String text;
public user(String name, int age, Strin
this.name = name;
this.age = age;
this.text = text;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
import java.util.*;
public class Test<use, pwd> {
static List list=new ArrayList();
static String[] use={"123","456","","",""};
static String[] pwd={"admin","user","","",""};
static boolean flag=false;
public static void main(String[] args) {
begin();
}
public static void begin() {
System.out.println("========欢迎进入用户管理系统=======");
System.out.println("请输入:1.登录 2.注册 3.发布博客 4.删除博客 5.修改博客 6.查看博客");
Scanner iu = new Scanner(System.in);
int n = iu.nextInt();
if (n == 1) {
Login();
begin();
} else if (n == 2) {
Registration();
begin();
} else if (n == 3) {
Add();
begin();
} else if (n == 4) {
Delete();
begin();
} else if (n == 5) {
Alter();
begin();
}else if (n==6){
Look();
begin();
}
else {
System.out.println("退出成功");
System.exit(0);
}
}
public static void Login() { //登录
Scanner iu = new Scanner(System.in);
System.out.print("请输入用户名:");
String a = iu.next();
System