华南师范机试13

一、编写一个程序,给出方程3x+2y-7z=5(其中,0≤x,y,z≤10),求满足方程的所有x,y和z,输出之。

public class thirteenYear {
    public static void main(String[] args) {
        for (int x = 0; x <= 10; x++){
            for (int y = 0; y <= 10; y++){
                for (int z = 0; z <= 10; z++){
                    if(3  * x + 2 * y - 7 * z == 5){
                        System.out.println(x+" "+y+" "+z);
                    }
                }
            }
        }
    }
}

二、编写函数,实现如下功能,键盘输入一个整数,判断每一个数字(0-9)在这个整数中重复出现的次数,输出重复出现的数字及其出现次数。比如:输入3321181,则输出3出现了2次、1出现了3次;输入2186,则输出没有重复数字。

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] shuzu = new int[10];
    while(n != 0){
        int yushu = n % 10;
        shuzu[yushu]+=1;
        n = n/10;
    }
    boolean flag = true;
    for (int i = 0;i< shuzu.length;i++){
        if(shuzu[i] > 1){
            System.out.println(i+"出现了"+shuzu[i]+"次");
        flag = false;
        }
    }
    if(flag) System.out.println("没有重复数字");
}

三、类Person是一个描述人员信息的数据结构体,包括姓名(不定长)、性别、年龄。利用该结构体创建数组emp[5],调用自身的Get()方法可以输入人员的信息,并通过Show()方法显示输入的信息。请编写程序完成上述功能

    public static void main(String[] args) {
        Person[] emp = new Person[5];
        for (int i = 0;i<emp.length;i++){
            emp[i] = new Person();
            emp[i].Get("张三"+i,"男",17+i);
        }
        for (Person person : emp) {
            person.Show();
        }
    }
class Person{
    String name;
    String sex;
    int age;
    public Person(){}
    public void Get(String name,String sex,int age){
        this.age = age;
        this.name = name;
        this.sex = sex;
    }
    public void Show(){
        System.out.println(name + " " + age + " " + sex);
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值