题解 | #统计输入正数个数#

创建单例对象

http://www.nowcoder.com/practice/9b316cd2d6264776918bc4bc31f37aec

饿汉式

public class Main {

public static void main(String[] args) {
    Singleton s1 = Singleton.getInstance();
    Singleton s2 = Singleton.getInstance();
    System.out.println(s1 == s2);
}

}

class Singleton {

private static Singleton instance = new Singleton();

private Singleton() {

}

//write your code here......
 
public static Singleton getInstance() {
    return instance;
}

}

全部评论

相关推荐

06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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