package com.bobo.regular;
public class RegularDemo01 {
/**
* 校验QQ号是否合法
* 1.必须是5~10位
* 2.0不可以作为QQ号开头
* @param args
*/
public static void main(String[] args) {
String str = "10232a1312";
System.out.println(checkQQ(str));
System.out.println(checkQQByRegular(str));
}
public static boolean checkQQByRegular(String qq){
// 正则表达式
String regex = "[1-9][0-9]{4,9}";
return qq.matches(regex);
}
/**
* 检查QQ号是否合法
* 1.必须是5~10位
* 2.0不可以作为QQ号开头
* 3.必须都是数字
*
* 检查输入的邮箱是否合法
* 1.名称又数字字母特殊符号组成
* 2.不能是数字开头
* 3.长度5~10位
* 4.含有@
* 5. .....
* @param qq
* @return
*/
public static boolean checkQQ(String qq)
{
boolean flag = false;
// 校验长度5~10位
if(qq.length() >= 5 && qq.length() <= 10){
// 保证不是0开头
if(!qq.startsWith("0")){
// 必须都是数字 988912a12312
char ch[] =qq.toCharArray();
flag = true;
for(char c : ch){
if(!Character.isDigit(c)){
flag = false;
break;
}
}
}
}
return flag;
}
}
a b c \t \n \r \f
/**
* 正则表达式的语法规则
*
* @param args
*/
public static void main(String[] args) {
// 原义字符
String regex = "a";
String str = " ab1 23dd34 sasdf&s; 234.";
System.out.println(str.replaceAll(regex, "X"));
regex = "\t";
System.out.println(str.replaceAll(regex, "X"));
}
Xb1 23dd34 sXsdf&s; 234.
ab1X23dd34Xsasdf&s;X234.
/**
* 正则表达式的语法规则
* 字符类
* @param args
*/
public static void main(String[] args) {
// 字符类 [abc]将字符进行了归类,可以出现[]中的其中任意一个字符 就会进行匹配
String regex = "[abc]";
String str = " ab1 23dd34 sasdf&s; 234.";
System.out.println(str.replaceAll(regex, "X"));
regex = "[^abc]"; // 取反 对不是 abc的字符进行匹配
System.out.println(str.replaceAll(regex, "X"));
}
XX1 23dd34 sXsdf&s; 234.
XabXXXXXXXXXXaXXXXXXXXXXX
package com.bobo.regular;
public class RegularDemo04 {
/**
* 正则表达式的语法规则
* 范围类 -
* @param args
*/
public static void main(String[] args) {
// 字符类 [a-z] 表示代表 a到z的所有的小写字母
String regex = "[a-z]";
String str = " ab1 ZZ 23dd34 A sasdf&s; SD 234.";
System.out.println(str.replaceAll(regex, "X"));
regex = "[a-zA-Z]";
System.out.println(str.replaceAll(regex, "X"));
regex = "[a-zA-Z0-9&;]";
System.out.println(str.replaceAll(regex, "X"));
}
}
XX1 ZZ 23XX34 A XXXXX&X; SD 234.
XX1 XX 23XX34 X XXXXX&X; XX 234.
XXX XX XXXXXX X XXXXXXXX XX XXX.
\d == [0-9] 数字
\D == [^0-9] 非数字
空白字符:[ \t\n\x0B\f\r] == \s
[^ \t\n\x0B\f\r] == \S
[a-zA-Z0-9] \w
[^a-zA-Z0-9] \W
. 任何字符(与行结束符可能匹配也可能不匹配)
package com.bobo.regular;
public class RegularDemo05 {
/**
* 正则表达式的语法规则
* 预定义类
* \d == [0-9] 数字
\D == [^0-9] 非数字
空白字符:[ \t\n\x0B\f\r] == \s
[^ \t\n\x0B\f\r] == \S
[a-zA-Z0-9] \w
[^a-zA-Z0-9] \W
. 任何字符(与行结束符可能匹配也可能不匹配)
* @param args
*/
public static void main(String[] args) {
// 字符类 [a-z] 表示代表 a到z的所有的小写字母
String regex = "\\d";//"[0-9]";
String str = " ab1 ZZ 23dd34 A sasdf&s; SD 234.";
System.out.println(str.replaceAll(regex, "X"));
regex = "\\D";
System.out.println(str.replaceAll(regex, "X"));
regex = "\\s";
System.out.println(str.replaceAll(regex, "X"));
regex = "\\w"; // 匹配字母和数字
System.out.println(str.replaceAll(regex, "*"));
regex = "\\W";
System.out.println(str.replaceAll(regex, "+"));
regex = "."; // . 表示 任何字符
System.out.println(str.replaceAll(regex, "+"));
regex = "\\."; // . 表示 任何字符 如果仅仅只是想要将.的字符匹配 用转意符
System.out.println(str.replaceAll(regex, "+"));
}
}
abX ZZ XXddXX A sasdf&s; SD XXX.
XXX1XXXX23XX34XXXXXXXXXXXXXXX234X
Xab1XZZX23dd34XAXsasdf&s;XSDX234.
*** ** ****** * *****&*; ** ***.
+ab1+ZZ+23dd34+A+sasdf+s++SD+234+
+++++++++++++++++++++++++++++++++
ab1 ZZ 23dd34 A sasdf&s; SD 234+
^:以XXX开头
$:以XXX结尾
\b:单词边界
\B:非单词边界
package com.bobo.regular;
public class RegularDemo06 {
/**
* 边界字符
* ^:以XXX开头
$:以XXX结尾
\b:单词边界
\B:非单词边界
* @param args
*/
public static void main(String[] args) {
String regex = "^ab"; // [^a]
String str = "abcdefg";
System.out.println(str.replaceAll(regex, "_"));
regex = "fg$"; // 表示以 fg 结尾
System.out.println(str.replaceAll(regex, "_"));
str = "Hello World 666 1 2 & ; 0 a b c d";
regex = "\\b";
System.out.println(str.replaceAll(regex, "_"));
regex = "\\B";
System.out.println(str.replaceAll(regex, "_"));
}
}
_cdefg
abcde_
_Hello_ _World_ _666_ _1_ _2_ & ; _0_ _a_ _b_ _c_ _d_
H_e_l_l_o W_o_r_l_d 6_6_6 1 2 _&_ _;_ 0 a b c d
package com.bobo.regular;
public class RegularDemo07 {
/**
* 量词
?:出现0次或者1次
+:出现1次或者多次
*:出现任意次
{n}:出现正好n次
{n,m}出现n-m次
{n,}出现至少n次
* @param args
*/
public static void main(String[] args) {
String regex = "^b?"; // [^a]
String str = "aaaabcdefg";
System.out.println(str.replaceAll(regex, "_"));
regex = "^b+"; // 以 0个或者1个b开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a+"; // 以 0个或者1个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a*"; // 以 任意个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a{4}"; // 以4个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a{3}"; // 以3个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a{5}"; // 以5个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a{5,6}"; // 以5到6个a开头
System.out.println(str.replaceAll(regex, "_"));
regex = "^a{3,}"; // 以3个以上的a开头
System.out.println(str.replaceAll(regex, "_"));
}
}
_aaaabcdefg
aaaabcdefg
_bcdefg
_bcdefg
_bcdefg
_abcdefg
aaaabcdefg
aaaabcdefg
_bcdefg
package com.bobo.regular;
public class RegularDemo08 {
/**
* 分组
* @param args
*/
public static void main(String[] args) {
// 匹配abc出现三组的情况
String regex = "(abc){3,}"; // [^a]
String str = "abcABC123123dbaCBAabcABCabcabcabc123";
System.out.println(str.replaceAll(regex, "*"));
regex = "ABC(123|abc){1,}"; // [^a]
System.out.println(str.replaceAll(regex, "-"));
}
}
abcABC123123dbaCBAabcABC*123
abc-dbaCBAabc
package com.bobo.regular;
public class RegularDemo09 {
/**
* 反向引用
* @param args
*/
public static void main(String[] args) {
// 2018-04-27 ==> 04/27/2018 分组中如果不想要生成分组编号可以通过 ?: 来实现
// String regex = "(\\d{4})-(?:\\d{2})-(\\d{2})";
String regex = "(\\d{4})-(\\d{2})-(\\d{2})";
String s = "2018-04-27";
String replace = s.replaceAll(regex, "$2/$3/$1");
System.out.println(replace);
}
}
04/27/2018
package com.bobo.regular;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularDemo10 {
/**
* 1.字符串的查找操作:Pattern和Matcher 2.字符串匹配操作:可以通过字符串的matchers方法 3.字符串的替换操作:
* 字符串的replaceAll()和replaceFirst()方法 4.字符串的分割: 字符串的split()方法
*
* @param args
*/
public static void main(String[] args) {
String regex = "\\w{3,7}";
String str = "abcd123";
System.out.println(str.matches(regex));
regex = "[a-z]{2,}";
System.out.println("abc efgsd hello111".replaceAll(regex, "X"));
System.out.println("abc efgsd hello111".replaceFirst(regex, "X"));
str = "abc,sdf 123ab sa123bds & ";
String[] s1 = str.split(",");
System.out.println(Arrays.toString(s1));
regex = "[as1]";
String[] s2 = str.split(regex);
System.out.println(Arrays.toString(s2));
// Pattern
// Pattern
regex = "\\w{3,7}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher("abcd123aaaa111dddd333");
// System.out.println(matcher.matches());
System.out.println(matcher.find());
System.out.println(matcher.end());
System.out.println(matcher.group());
System.out.println(matcher.find());
System.out.println(matcher.end());
System.out.println(matcher.group());
}
}
true
X X X111
X efgsd hello111
[abc, sdf 123ab sa123bds & ]
[, bc,, df , 23, b , , , 23bd, & ]
true
7
abcd123
true
14
aaaa111
规则如下:
• a.以1开头
• b.一共11位
• c.50结尾
• d.倒数第三位是9或者6
package com.bobo.regular;
public class RegularDemo11 {
/**
* 手机号验证
* 规则如下:
a.以1开头
b.一共11位
c.50结尾
d.倒数第三位是9或者6
* @param args
*/
public static void main(String[] args) {
String phoneNumber = "13888886950";
String regex = "^1\\d{7}[69](50)$";
System.out.println(phoneNumber.matches(regex));
}
}
On Friendship And a youth said, "Speak to us of Friendship." Your friend is your needs answered. He is your field which
package com.bobo.regular;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularDemo12 {
/**
* On Friendship And a youth said, "Speak to us of Friendship." Your friend is your needs answered. He is your field which
* @param args
*/
public static void main(String[] args) {
String s = " On Friendship And a youth said, \"Speak to us of Friendship.\" Your friend is your needs answered. He is your field which";
// 定义规则
String regex = "\\b[a-zA-Z]{2}\\b";
// 根据正则表达式编译生成模型对象
Pattern p = Pattern.compile(regex);
// 根据Pattern对象获取Matcher对象
Matcher matcher = p.matcher(s);
while(matcher.find()){
int start = matcher.start();
int end = matcher.end();
String group = matcher.group();
System.out.println(start + " " + end + " " + group);
}
/*boolean f1 = matcher.find();
System.out.println(f1);
int start1 = matcher.start();
int end1 = matcher.end();
String group1 = matcher.group();
System.out.println(start1 + " " + end1 + " " + group1);
boolean f2 = matcher.find();
System.out.println(f2);
int start2 = matcher.start();
int end2 = matcher.end();
String group2 = matcher.group();
System.out.println(start2 + " " + end2 + " " + group2);
boolean f3 = matcher.find();
System.out.println(f3);
int start3 = matcher.start();
int end3 = matcher.end();
String group3 = matcher.group();
System.out.println(start3 + " " + end3 + " " + group3);
boolean f4 = matcher.find();
System.out.println(f4);
int start4 = matcher.start();
int end4 = matcher.end();
String group4 = matcher.group();
System.out.println(start4 + " " + end4 + " " + group4);
*/
}
}
1 3 On
40 42 to
43 45 us
46 48 of
74 76 is
98 100 He
101 103 is
He is a man
This is a boy
is that your car?
isn't it?
What is your name?
package com.bobo.regular;
public class RegularDemo13 {
/**
* 将以下文章中的 is 替换为 IS He is a man This is a boy is that your car? isn't it?
* What is your name?
*
* @param args
*/
public static void main(String[] args) {
String s = "He is a man This is a boy is that your car? isn't it ? What is your name? ";
// System.out.println(s.replaceAll("is", "IS"));
String regex = "\\bis\\b";
System.out.println(s.replaceAll(regex, "IS"));
}
}
He IS a man This IS a boy IS that your car? isn't it ? What IS your name?
2016/03/05
demo/07/ss
1993/08/05
2016/11/24
12345/23/45678
12345/24/3356
1993-08-05
package com.bobo.regular;
public class RegularDemo14 {
/**
* 将以下字符串中正确的日期格式替换为 MM-dd-yyyy
* 2016/03/05
* demo/07/ss
* 1993/08/05
* 2016/11/24
* 12345/23/45678
* 12345/24/3356
* 1993-08-05
*
* @param args
*/
public static void main(String[] args) {
String s = "2016/03/05\r\n "
+ "demo/07/ss\r\n "
+ "1993/08/05\r\n "
+ "2016/11/24\r\n "
+ "12345/23/45678\r\n "
+ "12345/24/3356\r\n "
+ "1993-08-05";
String regex = "\\b(\\d{4})[/-](\\d{2})[/-](\\d{2})\\b";
System.out.println(s.replaceAll(regex, "$2-$3-$1"));
}
}
03-05-2016
demo/07/ss
08-05-1993
11-24-2016
12345/23/45678
12345/24/3356
08-05-1993
验证正则表达式
整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$
只能输入数字:"^[0-9]*$"。
只能输入n位的数字:"^\d{n}$"。
只能输入至少n位的数字:"^\d{n,}$"。
只能输入m~n位的数字:。"^\d{m,n}$"
只能输入零和非零开头的数字:"^(0|[1-9][0-9]*)$"。
只能输入有两位小数的正实数:"^[0-9]+(.[0-9]{2})?$"。
只能输入有1~3位小数的正实数:"^[0-9]+(.[0-9]{1,3})?$"。
只能输入非零的正整数:"^\+?[1-9][0-9]*$"。
只能输入非零的负整数:"^\-[1-9][]0-9"*$。
只能输入长度为3的字符:"^.{3}$"。
只能输入由26个英文字母组成的字符串:"^[A-Za-z]+$"。
只能输入由26个大写英文字母组成的字符串:"^[A-Z]+$"。
只能输入由26个小写英文字母组成的字符串:"^[a-z]+$"。
只能输入由数字和26个英文字母组成的字符串:"^[A-Za-z0-9]+$"。
只能输入由数字、26个英文字母或者下划线组成的字符串:"^\w+$"。
验证用户密码:"^[a-zA-Z]\w{5,17}$"正确格式为:以字母开头,长度在6~18之间,只能包含字符、数字和下划线。
验证是否含有^%&'',;=?$\"等字符:"[^%&'',;=?$\x22]+"。
只能输入汉字:"^[\u4e00-\u9fa5]{0,}$"
验证Email地址:"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"。
验证InternetURL:"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$"。
验证电话号码:"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$"正确格式为:"XXX-XXXXXXX"、"XXXXXXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX"。
验证身份证号(15位或18位数字):"^\d{15}|\d{18}$"。
验证一年的12个月:"^(0?[1-9]|1[0-2])$"正确格式为:"01"~"09"和"1"~"12"。
验证一个月的31天:"^((0?[1-9])|((1|2)[0-9])|30|31)$"正确格式为;"01"~"09"和"1"~"31"。
package com.bobo.enums;
/**
* 枚举类
* 实现的方式有两种:
* 1.jdk1.5之前我们需要自定义枚举类
* 2.jdk1.5 我们可以通过enum来实现
* @author dpb
*
*/
public class EnumDemo01 {
public static void main(String[] args) {
Season spring = Season.SPRING;
Season summer = Season.SUMMER;
Season autumn = Season.AUTUMN;
Season winter = Season.WINTER;
System.out.println(spring.getSEASON_NAME());
System.out.println(summer.getSEASON_NAME());
System.out.println(autumn.getSEASON_NAME());
System.out.println(winter.getSEASON_NAME());
}
}
/**
* 自定义一个季节的枚举类
*/
class Season{
// 2.创建Season的属性
private final String SEASON_NAME;
private final String SEASON_DESC;
// 1.要保证类的对象的个数是有限的,那么我们就必须要私有化构造方法
private Season(String SEASON_NAME,String SEASON_DESC){
this.SEASON_NAME = SEASON_NAME;
this.SEASON_DESC = SEASON_DESC;
}
// 3.提供公有的静态属性给外界获取枚举类的多个对象
public static final Season SPRING = new Season("春天", "万物复苏");
public static final Season SUMMER = new Season("夏天", "夏日炎炎");
public static final Season AUTUMN = new Season("秋天", "秋高气爽");
public static final Season WINTER = new Season("冬天", "冰天雪地");
// 4.提供获取 SEASON_NAME 和 SEASON_DESC的共有方法
public String getSEASON_NAME() {
return SEASON_NAME;
}
public String getSEASON_DESC() {
return SEASON_DESC;
}
// 5.重写toString方法
@Override
public String toString() {
return "Season [SEASON_NAME=" + SEASON_NAME + ", SEASON_DESC=" + SEASON_DESC + "]";
}
}
package com.bobo.enums2;
import java.util.Arrays;
/**
* 枚举类
* 实现的方式有两种:
* 1.jdk1.5之前我们需要自定义枚举类
* 2.jdk1.5 我们可以通过enum来实现
* @author dpb
*
*/
public class EnumDemo01 {
public static void main(String[] args) {
Season spring = Season.SPRING;
Season summer = Season.SUMMER;
Season autumn = Season.AUTUMN;
Season winter = Season.WINTER;
System.out.println(spring);
System.out.println(summer);
System.out.println(autumn);
System.out.println(winter);
System.out.println(Season.class.getSuperclass());
}
}
/**
* 自定义一个季节的枚举类
*/
enum Season{
// 3.枚举有的有限的对象 对象之间通过,连接 最后一个通过;结尾
SPRING("春天", "万物复苏"),
SUMMER("夏天", "夏日炎炎"),
AUTUMN("秋天", "秋高气爽"),
WINTER("冬天", "冰天雪地");
// 2.创建Season的属性
private final String SEASON_NAME;
private final String SEASON_DESC;
// 1.要保证类的对象的个数是有限的,那么我们就必须要私有化构造方法
private Season(String SEASON_NAME,String SEASON_DESC){
this.SEASON_NAME = SEASON_NAME;
this.SEASON_DESC = SEASON_DESC;
}
// 4.提供获取 SEASON_NAME 和 SEASON_DESC的共有方法
public String getSEASON_NAME() {
return SEASON_NAME;
}
public String getSEASON_DESC() {
return SEASON_DESC;
}
// 5.重写toString方法
/* @Override
public String toString() {
return "Season [SEASON_NAME=" + SEASON_NAME + ", SEASON_DESC=" + SEASON_DESC + "]";
}*/
}
package com.bobo.enums2;
import java.util.Arrays;
/**
* 枚举类
* 实现的方式有两种:
* 1.jdk1.5之前我们需要自定义枚举类
* 2.jdk1.5 我们可以通过enum来实现
* @author dpb
*
*/
public class EnumDemo01 {
public static void main(String[] args) {
Season spring = Season.SPRING;
Season summer = Season.SUMMER;
Season autumn = Season.AUTUMN;
Season winter = Season.WINTER;
System.out.println(spring);
System.out.println(summer);
System.out.println(autumn);
System.out.println(winter);
System.out.println(Season.class.getSuperclass());
System.out.println("************");
// Enum中的常用方法
// values() 获取枚举对象的数组,该方法可以很方便的遍历出所有的枚举对象的值
Season[] values = Season.values();
System.out.println(Arrays.toString(values));
// valueOf 根据枚举对象的名称获取对应的枚举对象 如果不存在就抛
// java.lang.IllegalArgumentException:
Season summer1 = Season.valueOf("SUMMER");
System.out.println(summer1);
// toString:打印枚举对象的名称
}
}
/**
* 自定义一个季节的枚举类
*/
enum Season{
// 3.枚举有的有限的对象 对象之间通过,连接 最后一个通过;结尾
SPRING("春天", "万物复苏"),
SUMMER("夏天", "夏日炎炎"),
AUTUMN("秋天", "秋高气爽"),
WINTER("冬天", "冰天雪地");
// 2.创建Season的属性
private final String SEASON_NAME;
private final String SEASON_DESC;
// 1.要保证类的对象的个数是有限的,那么我们就必须要私有化构造方法
private Season(String SEASON_NAME,String SEASON_DESC){
this.SEASON_NAME = SEASON_NAME;
this.SEASON_DESC = SEASON_DESC;
}
// 4.提供获取 SEASON_NAME 和 SEASON_DESC的共有方法
public String getSEASON_NAME() {
return SEASON_NAME;
}
public String getSEASON_DESC() {
return SEASON_DESC;
}
// 5.重写toString方法
/* @Override
public String toString() {
return "Season [SEASON_NAME=" + SEASON_NAME + ", SEASON_DESC=" + SEASON_DESC + "]";
}*/
}
package com.bobo.enums3;
import java.util.Arrays;
/**
* 枚举类
* 实现的方式有两种:
* 1.jdk1.5之前我们需要自定义枚举类
* 2.jdk1.5 我们可以通过enum来实现
* @author dpb
*
*/
public class EnumDemo01 {
public static void main(String[] args) {
Season spring = Season.SPRING;
Season summer = Season.SUMMER;
Season autumn = Season.AUTUMN;
Season winter = Season.WINTER;
spring.show();
summer.show();
}
}
interface Person{
void show();
}
/**
* 自定义一个季节的枚举类
*/
enum Season implements Person{
// 3.枚举有的有限的对象 对象之间通过,连接 最后一个通过;结尾
SPRING("春天", "万物复苏"),
SUMMER("夏天", "夏日炎炎"),
AUTUMN("秋天", "秋高气爽"),
WINTER("冬天", "冰天雪地");
// 2.创建Season的属性
private final String SEASON_NAME;
private final String SEASON_DESC;
// 1.要保证类的对象的个数是有限的,那么我们就必须要私有化构造方法
private Season(String SEASON_NAME,String SEASON_DESC){
this.SEASON_NAME = SEASON_NAME;
this.SEASON_DESC = SEASON_DESC;
}
// 4.提供获取 SEASON_NAME 和 SEASON_DESC的共有方法
public String getSEASON_NAME() {
return SEASON_NAME;
}
public String getSEASON_DESC() {
return SEASON_DESC;
}
// 5.重写toString方法
/* @Override
public String toString() {
return "Season [SEASON_NAME=" + SEASON_NAME + ", SEASON_DESC=" + SEASON_DESC + "]";
}*/
@Override
public void show() {
System.out.println("今天是个好天气");
}
}
package com.bobo.enums4;
import java.util.Arrays;
/**
* 枚举类
* 实现的方式有两种:
* 1.jdk1.5之前我们需要自定义枚举类
* 2.jdk1.5 我们可以通过enum来实现
* @author dpb
*
*/
public class EnumDemo01 {
public static void main(String[] args) {
Season spring = Season.SPRING;
Season summer = Season.SUMMER;
Season autumn = Season.AUTUMN;
Season winter = Season.WINTER;
spring.show();
summer.show();
}
}
interface Person{
void show();
}
/**
* 自定义一个季节的枚举类
*/
enum Season implements Person{
// 3.枚举有的有限的对象 对象之间通过,连接 最后一个通过;结尾
SPRING("春天", "万物复苏"){
@Override
public void show() {
System.out.println("春天来了");
}
},
SUMMER("夏天", "夏日炎炎"){
@Override
public void show() {
System.out.println("好热啊");
}
},
AUTUMN("秋天", "秋高气爽"){
@Override
public void show() {
System.out.println("真舒服");
}
},
WINTER("冬天", "冰天雪地"){
@Override
public void show() {
System.out.println("羽绒服搞起来");
}
};
// 2.创建Season的属性
private final String SEASON_NAME;
private final String SEASON_DESC;
// 1.要保证类的对象的个数是有限的,那么我们就必须要私有化构造方法
private Season(String SEASON_NAME,String SEASON_DESC){
this.SEASON_NAME = SEASON_NAME;
this.SEASON_DESC = SEASON_DESC;
}
// 4.提供获取 SEASON_NAME 和 SEASON_DESC的共有方法
public String getSEASON_NAME() {
return SEASON_NAME;
}
public String getSEASON_DESC() {
return SEASON_DESC;
}
}