7-1 把大象装进冰箱(继承)

这篇博客通过一个趣味性的例子——把大象装进冰箱,解释了Java中的继承概念。作者用代码展示了如何创建动物类和电器类,并演示了如何将动物对象放入电器对象(如微波炉)中,以此说明类之间的继承关系和对象的操作过程。
摘要由CSDN通过智能技术生成

7-1 把大象装进冰箱(继承) (100 分)
把大象装入冰箱(继承).docx

输入格式:
Put the 动物类名 动物名字 into the 电器类名 电器名字。例如:Put the Lion Jack into the Microvate Robert。

输出格式:
create 电器类名 电器名字 create 动物类名 动物名字 电器类名 电器名字 is open 动物类名 动物名字 is in 电器类名 电器名字 电器类名 电器名字 is close

输入样例:
在这里给出一组输入。例如:

Put the Lion Jack into the Microwave Robert
输出样例:
在这里给出相应的输出。例如:

create Microwave Robert
create Lion Jack
Microwave Robert is open
Lion Jack is in Microwave Robert
Microwave Robert is close

import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Main {
   
    public static void main(String[] args) {
   
        //Scannner input = new Scanner(System.in);
    	Scanner input = new Scanner(System.in);
        String temp = input.nextLine();
        String regex = "Put\\s+the\\s+(\\w+)\\s+(\\w+)\\s+into\\s+the\\s+(\\w+)\\s+(\\w+)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(temp);
        if(matcher.find()) {
   
            String animalClass = matcher.group(1);//动物
            String animalName = matcher.group(2);//动物名字
            String electricClass = matcher.group(3)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值