Java作业之面向对象篇

 

作业:
    给定一个大小为 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
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南孚程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值