java学习笔记10

java学习笔记10

知识点

1.获取字符串长度

字符串名.length();

2.自定义快捷输入

在IDEA中,通过File → Settings → Editor → Live Templates
例如:
在这里插入图片描述
只要输入buff ,就会直接输入BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
在这里插入图片描述
只要输入ssrl ,就会输入String s$END$ = reader.readLine(); ,并且输入光标停留在$END$处。

3.类创建的流程

类基本上是按以下流程创建的:

  1. 程序员确定需要哪些其他对象。

  2. 程序员根据对象要执行的操作将其分为不同的类型。

  3. 程序员为每种类型编写单独的类。

  4. 在类中,程序员声明所需的方法和变量。

  5. 在每种方法中,程序员编写命令以使该方法执行所需的操作。

  6. 类已完成。现在你可以创建该类的对象。

任务

课程1 比较和设置条件

任务1 两个数字中的最小值

package zh.codegym.task.task04.task0418;

/* 
两个数字中的最小值
使用键盘输入两个整数,然后显示最小值。如果这两个数字相等,则显示其中任一数字。
*/

import java.io.*;

public class Solution {
   
    public static void main(String[] args) throws Exception {
   
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String sA = reader.readLine();
        String sB = reader.readLine();
        int a = Integer.parseInt(sA);
        int b = Integer.parseInt(sB);
        if(a < b){
   
            System.out.println(a);
        }else{
   
            System.out.print(b);
        }
        //在此编写你的代码
    }
}

任务2 四个数字中的最大值

package zh.codegym.task.task04.task0419;

/* 
四个数字中的最大值
使用键盘输入四个数字,然后显示其中的最大值。如果最大值出现多次,则只显示一次。
*/

import java.io.*;

public class Solution {
   
    public static void main(String[] args) throws Exception {
   
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String sA = reader.readLine();
        String sB = reader.readLine();
        String sC = reader.readLine();
        String sD = reader.readLine();
        int a = Integer.parseInt(sA);
        int b = Integer.parseInt(sB);
        int c = Integer.parseInt(sC);
        int d = Integer.parseInt(sD);
        int max = 0 ;
        if (a > b) {
   
            max = a;
        } else {
   
            max = b;
        }
        if (c > max) {
   
            max = c;
        }
        if (d > max) {
   
            max = d;
        }
        System.out.println(max);
        //在此编写你的代码
    }
}

任务3 对三个数字进行排序

使用键盘输入三个数字,然后按降序显示它们。
所显示的数字必须用空格分隔。

package zh.codegym.task.task04.task0420;

/* 
对三个数字进行排序
*/

import java.io.*;

public class Solution {
   
    public static void main(String[] args) throws Exception {
   
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String sA = reader.readLine();
        String sB = reader.readLine();
        String sC = reader.readLine();
        int a = Integer.parseInt(sA);
        int b = Integer.parseInt(sB);
        int c = Integer.parseInt(sC);
        int tmp = 0;
        if (a > b) {
   
            if (c > a) {
   
                tmp = a;
                a = c;
                c = tmp;
                tmp = b;
                b = c;
                c = tmp;
            } else if (c > b) {
   
                tmp = b;
                b = c;
                c = tmp;
            }
        } else {
   
            tmp = b;
            b = a;
            a = tmp;
            if (c > a) {
   
                tmp = a;
                a = c;
                c = tmp;
                tmp = b;
                b = c;
                c = tmp;
            } else if (c > b) {
   
                tmp = b;
                b = c;
                c = tmp;
            }
        }
        System.out.println(a + " " + b + " " + c);
    }
}

任务4 珍或珍?

使用键盘输入两个名字。如果这两个名字相同,则显示“名字相同”。
如果这两个名字不同,但它们的长度相同,则显示“名字长度相同”。
如果这两个名字和名字长度都不相同,则不显示任何内容。

package zh.codegym.task.task04.task0421;

/* 
珍或珍?
*/

import java.io.*;

public class Solution {
   
    public static void main(String[] args) throws Exception {
   
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String sName1 = reader.readLine();
        String sName2 = reader.readLine();
        if (sName1.equals(sName2)) {
   
            System.out.println("名字相同");
        } else if (sName1.length() == sName2.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值