笔头练习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//输入一个值 查找对应数组中元素的索引
import java.util.Scanner;
 
public class Test06 {
    public static void main(String[] args) {
        int[] arr = {19, 28, 37, 46, 50};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入查找的数据: ");
        int number = sc.nextInt();
 
        /*int index = -1;
        for(int x = 0; x<arr.length; x++){
            if(arr[x] == number){
                index = x;
                break;
            }
        } */
        int index = getIndex(arr, number);
        System.out.println("index: " + index);
    }
 
    /*方法调用2个明确:
        返回值类型:int
        参数:int[] arr,int number
     */
    public static int getIndex(int[] arr, int number) {
        int index = -1;
        for (int x = 0; x < arr.length; x++) {
            if (arr[x] == number) {
                index = x;
                break;
            }
        }
        return index;
    }
}
 
 
 
//用方法 判断数组是否相同
public class Test01 {
    public static void main(String[] args) {
        int[] arr = {11,22,33,44,55,66};
        int[] arr2 = {11,22,33,44,55,66};
 
        boolean flag = compare(arr,arr2);
        System.out.println(flag);
 
    }
    public static boolean compare(int[] arr, int[] arr2){
        if(arr.length != arr2.length){
            return false;
        }
        for(int x = 0; x<arr.length; x++){
            if(arr[x] != arr2[x]){
                return false;
            }
        }
        return true;
    }
}
 
 
//百钱百鸡
//一个公鸡5钱,一个母鸡3钱,一钱买3个小鸡,,共有100文钱
public class Test03 {
    public static void main(String[] args) {
        for (int x = 0; x <= 20; x++) {
            for (int y = 0; y <= 33; y++) {
                int z = 100 - x - y;
 
                if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
                    System.out.println(x + "," + y + "," + z);
                }
 
            }
        }
    }
}
 
 
//不死兔
public class Test04 {
    public static void main(String[] args) {
        int[] arr = new int[20];
        arr[0] = 1;
        arr[1] = 1;
 
        for(int x=2; x<arr.length;x++){
             arr[x] = arr[x-2] + arr[x - 1];
        }
        System.out.println("第二十个月兔子的对数: " + arr[19]);
 
    }
}
 
 
//求数组中数据 个位 十位都不能为7 且能被2整除的数据的和
public class Test02 {
    public static void main(String[] args) {
        int[] arr = {68,27,95,88,171,996,51,210};
        int sum = 0;
 
        for(int x = 0; x<arr.length; x++){
            if(arr[x]%10!=7 && arr[x]/10%10!=7 && arr[x]%2 == 0){
                sum += arr[x];
            }
        }
        System.out.println("sum: " + sum);
    }
}
 
 
//1-100之间逢七过
public class Test05 {
    public static void main(String[] args) {
        for(int x = 1;x <= 100;x++){
            if(x%10==7 || x/10%10==7 || x%7 ==0)
                System.out.println(x);
        }
    }
}

  

posted @   walkersss  阅读(28)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· DeepSeek “源神”启动!「GitHub 热点速览」
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
点击右上角即可分享
微信分享提示