题解 | #定义打印方法#

定义打印方法

http://www.nowcoder.com/practice/50b50ae39d65415a9fd70601d711e5af

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
        String className = scanner.next();
        // print就是需要你定义的方法
        print(Class.forName(className).newInstance());
    }
}

//write your code here......
public static void print(Object obj){
    System.out.print(obj.toString());
}

}

class First { public String toString() { return "First"; } }

class Second { public String toString() { return "Second"; } }

class Third { public String toString() { return "Third"; } }

全部评论

相关推荐

感觉面试官对我的实习不太满意,唉
皮格吉:我已经复活一次了,下周继续打复活赛,我已经把他家当成秋招电子宠物了
我的秋招日记
点赞 评论 收藏
分享
也许是天气_:实习这块全是假大空像AI生成的,没有实际内容。要体现出难点、亮点、解决问题的过程
点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务