| public class Test { 
 public static void main(String[] args) {
 makeShape(14);
 }
 
 public static void makeShape(int needLength) {
 if (needLength > 30) {
 System.out.println("不要太过分!日");
 return;
 }
 for (int i = 0; i < needLength; i++) {
 for (int j = i; j < needLength-1; j++) {
 System.out.print(" ");
 }
 for (int j = 0; i >= j; j++) {
 System.out.print("* ");
 }
 System.out.println();
 }
 for (int i = 0; i < needLength; i++) {
 for (int j = 0; i >= j; j++) {
 System.out.print(" ");
 }
 for (int j = i; j < needLength-1; j++) {
 System.out.print("* ");
 }
 System.out.println();
 }
 }
 
 private int x = 100; // 成员变量 / 属性 / 字段 指的都是它 名字好几个呢
 
 // 叫函数的是它 叫方法的也是它
 public void 呵呵() {
 int xx = x; // 这里的xx 叫 局部变量 , 必须初始化值 什么叫初始化? 你就理解给它个默认值
 System.out.println(xx);
 }
 
 public void hehe() {
 
 }
 
 public Test() {
 System.out.println("无参构造函数");
 }
 
 public Test(int x) {
 System.out.println(x);
 System.out.println("有参构造函数1");
 }
 
 public Test(int x, int y, int z) {
 System.out.println(x + "" + y + "" + z);
 System.out.println("有参构造函数2");
 }
 
 public Test(int x, int y) {
 System.out.println(x + "--" + y);
 System.out.println("有参构造函数3");
 }
 
 }
 
 /**
 * 单例 1
 *
 * @Description:饿汉
 */
 class Single01 {  // 不能被public修饰  public class Single01 是错误的
 private Single01() {
 }
 
 private static Single01 single = new Single01();
 
 public static Single01 getInstance() {
 return single;
 }
 }
 
 /**
 * 单例 2
 *
 * @Description:懒汉
 */
 class Single02 {     // 不能被public修饰  public class Single02 是错误的
 private Single02() {
 }
 
 private static Single02 single = null;
 
 public static Single02 getInstance() {
 if (single == null) {
 single = new Single02();
 }
 return single;
 }
 }
 |