2020-07-25日报博客

2020-07-25日报博客

1.完成的事情:

  • 完成CodeGym Java基础leve 5 和 level 6部分,并完成练习题
  • 阅读《大道至简》。

2.遇到的问题:

  • 类定义时权限修饰符的使用。

3.明日计划:

  • 继续学习Java。
  • 阅读《大道至简》。
/*taskKey="zh.codegym.task.task05.task0532"

有关算法的任务

编写程序,使其:
1. 从控制台读取数字 N(必须大于 0)
2. 从控制台读取 N 个数字
3.显示 N 个输入数字中的最大值。


Requirements:
1.	程序应从键盘读取这些数字。
2.	程序必须在屏幕上显示一个数字。
3.	该类必须包含 public static void main 方法。
4.	不要向 Solution 类添加新方法。
5.	程序应显示 N 个输入数字中的最大值。
6.	如果 N 小于或等于 0,程序不应显示任何内容。*/


package zh.codegym.task.task05.task0532;

import java.io.*;

/* 
有关算法的任务
*/

public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(reader.readLine());

        if (N > 0) {
            int maximum = Integer.parseInt(reader.readLine());
            for (int i = 0; i < N - 1; i++) {
                int t = Integer.parseInt(reader.readLine());
                maximum = maximum > t ? maximum : t;
            }
            System.out.println(maximum);
        }
    }
}

/*taskKey="zh.codegym.task.task05.task0531"

改进功能

当前实现:程序从键盘读取两个数字并显示最小值。
新任务:程序从键盘读取五个数字并显示最小值。


Requirements:
1.	程序应从键盘读取这些数字。
2.	该类必须包含 public static void main 方法。
3.	该类必须包含带 5 个参数的 public static min 方法。
4.	min 方法必须返回所传递的 5 个数字中的最小值。如果有多个最小数字,则返回其中任意一个。
5.	程序应显示以&ldquo;最小值 = &rdquo;开头的字符串。
6.	程序应显示以五个输入数字中的最小值结尾的字符串。*/


package zh.codegym.task.task05.task0531;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/* 
改进功能
*/

public class Solution {

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(reader.readLine());
        int b = Integer.parseInt(reader.readLine());
        int c = Integer.parseInt(reader.readLine());
        int d = Integer.parseInt(reader.readLine());
        int e = Integer.parseInt(reader.readLine());

        int minimum = min(a, b, c, d, e);

        System.out.println("最小值 = " + minimum);
    }


    public static int min(int a, int b) {
        return a < b ? a : b;
    }

    public static int min(int a, int b, int c, int d, int e){
        int minimum = min(a, b);
        minimum = min(minimum,c);
        minimum = min(minimum,d);
        minimum = min(minimum,e);
        return minimum;
    }
}
原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/13448919.html