标签:demo compile 并且 divide bool 多次 time() 常用 字母
package com.xuweiwei; import java.util.Scanner; public class QQDemo { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入你的QQ号码:"); String qq = input.next(); String result = checkQQ(qq) == true ?"正确":"错误"; System.out.println("QQ格式"+result); } public static boolean checkQQ(String qq){ boolean flag = true; if(qq.length() >=5 && qq.length() <=15){ if(!qq.startsWith("0")){ char[] chars = qq.toCharArray(); for (char aChar : chars) { if(!Character.isDigit(aChar)){ flag = false; break; } } }else{ //不满足开头为0 flag = false; } }else { //如果不满足5-15位 flag = false; } return flag; } }
package com.xuweiwei; import java.util.Scanner; public class QQDemo2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入你的QQ号码:"); String qq = input.next(); String result = checkQQ(qq) == true ? "正确" : "错误"; System.out.println("QQ格式" + result); } private static boolean checkQQ(String qq) { String regex = "[1-9][0-9]{4,14}]"; return qq.matches(regex); } }
public boolean matches(String regex)
public String[] split(String regex)
public String replaceAll(String regex,String replacement)
Pattern和Matcher类的使用
package com.xuweiwei.demo1; import java.util.Scanner; /** * 判断手机号码是否满足要求? */ public class RegexDemo1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入你的手机号码:"); String phone = input.next(); //定义手机号码的规则 String regex = "(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}"; String result = phone.matches(regex) == true?"手机号码合法":"手机号码不合法"; System.out.println(result); } }
package com.xuweiwei.demo1; import java.util.Scanner; public class RegexDemo2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入邮箱:"); String email = input.next(); String regex = "[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}"; String result = email.matches(regex) == true ? "邮箱合法" : "邮箱不合法"; System.out.println(result); } }
package com.xuweiwei.demo1; public class RegexDemo3 { public static void main(String[] args) { String ages = "18-24"; String regex = "-"; String[] ageArray = ages.split(regex); for (String s : ageArray) { System.out.println(s); } } }
package com.xuweiwei.demo1; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexDemo4 { public static void main(String[] args) { /** * 模式和匹配器的典型应用 */ //把正则表达式编译成模式对象 Pattern p = Pattern.compile("a*b"); //通过模式对象得到匹配器对象,这个时候被匹配的字符串 Matcher m = p.matcher("aaaab"); //调用匹配器的matches的功能 boolean result = m.matches(); System.out.println("result:" + result); } }
package com.xuweiwei.demo1; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 获取三个字符组成的单词 */ public class RegexDemo5 { public static void main(String[] args) { String str = "da jia ting wo shuo,jin tian yao xia yu,bu shang wan zi xi,gao xing bu?"; String regex = "\\b\\w{3}\\b"; //把规则编译成模式对象 Pattern p = Pattern.compile(regex); //通过模式对象得到匹配器对象 Matcher matcher = p.matcher(str); //通过find方法就是查找有没有满足条件的子串 while (matcher.find()){ System.out.println(matcher.group()); } } }
public Random()
public Random(long seed)
public int nextInt()
public int nextInt(int n)
package com.xuweiwei.demo1; import java.util.Random; public class RandomDemo { public static void main(String[] args) { Random random = new Random(); for (int i = 0; i < 100; i++) { int num = random.nextInt(100) + 1; System.out.println(num); } } }
public static void gc()
public static void exit(int status)
public static long currentTimeMillis()
public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
package com.xuweiwei.demo1; import java.util.Arrays; public class SystemDemo { public static void main(String[] args) { int[] arr = {11,22,33,44,55}; int[] arr2 = {6,7,8,9,10}; System.arraycopy(arr,1,arr2,2,2); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); } }
package com.xuweiwei.demo1; import java.math.BigInteger; public class BigIntegerDemo { public static void main(String[] args) { BigInteger b = new BigInteger("2147483648"); System.out.println(b); } }
package com.xuweiwei.demo1; public class BigDecimalDemo { public static void main(String[] args) { System.out.println(0.09 + 0.01); System.out.println(1.0 - 0.32); System.out.println(1.015 * 100); System.out.println(1.301 / 100); } }
package com.xuweiwei.demo1; import java.math.BigDecimal; public class BigDecimalDemo { public static void main(String[] args) { BigDecimal d1 = new BigDecimal("0.09"); BigDecimal d2 = new BigDecimal("0.01"); System.out.println(d1.add(d2)); d1 = new BigDecimal("1.0"); d2 = new BigDecimal("0.32"); System.out.println(d1.subtract(d2)); d1 = new BigDecimal("1.015"); d2 = new BigDecimal("100"); System.out.println(d1.multiply(d2)); d1 = new BigDecimal("1.301"); d2 = new BigDecimal("100"); System.out.println(d1.divide(d2)); } }
public Date()
public Date(long date)
public long getTime()
public void setTime(long time)
package com.xuweiwei.demo1; import java.util.Date; public class DateDemo { public static void main(String[] args) { Date d = new Date(); System.out.println(d); Date d2 = new Date(System.currentTimeMillis()); System.out.println(d2); } }
package com.xuweiwei.demo1; import java.util.Date; public class DateDemo { public static void main(String[] args) { Date d = new Date(); long time = d.getTime(); System.out.println(time); } }
public SimpleDateFormat()
public SimpleDateFormat(String pattern)
public final String format(Date date)
public Date parse(String source) throws ParseException
package com.xuweiwei.demo1; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class SimpleDateFormatDemo { public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //String --> Date Date date = sdf.parse("2018-04-02 12:12:12"); System.out.println(date); //Date --> String String str = sdf.format(new Date()); System.out.println(str); } }
public static Calendar getInstance()
public int get(int field)
public final void set(int year, int month,int date)
public abstract void add(int field, int amount)
package com.xuweiwei.demo1; import java.util.Calendar; public class CalendarDemo { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); //获取年 int year = calendar.get(Calendar.YEAR); //获取月 int month = calendar.get(Calendar.MONTH); //获取日 int day = calendar.get(Calendar.DAY_OF_MONTH); System.out.println(year+"-"+(month+1)+"-"+day); } }
package com.xuweiwei.demo1; import java.util.Calendar; public class CalendarDemo2 { public static void main(String[] args) { //获取当前的日历时间 Calendar calendar = Calendar.getInstance(); //获取年 int year = calendar.get(Calendar.YEAR); //获取月 int month = calendar.get(Calendar.MONTH); //获取日 int day = calendar.get(Calendar.DATE); System.out.println(year+"-"+(month+1)+"-"+day); //三年前的今天 calendar.add(Calendar.YEAR,-3); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Calendar.DAY_OF_MONTH); System.out.println(year+"-"+(month+1)+"-"+day); } }
标签:demo compile 并且 divide bool 多次 time() 常用 字母
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9315553.html