分割
来源:互联网 发布:银行数据标准定义规范 编辑:程序博客网 时间:2024/06/09 20:13
import java.util.Scanner;
/*
* 分割功能
* String类的public String[] split(String regex)
* 根据给定正则表达式的匹配拆分此字符串。
*
* 举例:
* 百合网,世纪佳缘,珍爱网,QQ
* 搜索好友
* 性别:女
* 范围:"18-24"
*
* age>=18 && age<=24
*/
public class RegexDemo {
public static void main(String[] args) {
//定义一个年龄搜索范围
String ages = "18-24";
//定义规则
String regex = "-";
//调用方法
String[] strArray = ages.split(regex);
// //遍历
// for(int x=0; x<strArray.length; x++){
// System.out.println(strArray[x]);
// }
//如何得到int类型的呢?
int startAge = Integer.parseInt(strArray[0]);
int endAge = Integer.parseInt(strArray[1]);
//键盘录入年龄
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的年龄:");
int age = sc.nextInt();
if(age>=startAge && age<=endAge) {
System.out.println("你就是我想找的");
}else {
System.out.println("不符合我的要求");
}
}
}
/*
* 分割功能
* String类的public String[] split(String regex)
* 根据给定正则表达式的匹配拆分此字符串。
*
* 举例:
* 百合网,世纪佳缘,珍爱网,QQ
* 搜索好友
* 性别:女
* 范围:"18-24"
*
* age>=18 && age<=24
*/
public class RegexDemo {
public static void main(String[] args) {
//定义一个年龄搜索范围
String ages = "18-24";
//定义规则
String regex = "-";
//调用方法
String[] strArray = ages.split(regex);
// //遍历
// for(int x=0; x<strArray.length; x++){
// System.out.println(strArray[x]);
// }
//如何得到int类型的呢?
int startAge = Integer.parseInt(strArray[0]);
int endAge = Integer.parseInt(strArray[1]);
//键盘录入年龄
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的年龄:");
int age = sc.nextInt();
if(age>=startAge && age<=endAge) {
System.out.println("你就是我想找的");
}else {
System.out.println("不符合我的要求");
}
}
}
0 0
- 分割
- 分割
- 分割
- 分割
- 分割
- 分割
- 分割
- 分割字符
- 分割显示
- 分割字符串
- 图像分割
- 分割字符串
- 短消息分割
- 分割窗口
- 分割符
- 分割字符串
- 分割字符串
- 分割字符串
- UVA1339
- 48. Rotate Image 旋转矩阵的通用方法
- computer networks outline (1)
- 如何读懂并写出装逼的函数式代码
- 内联函数&宏替换
- 分割
- 【C++】 C++标准模板库(九) Bitsets
- 关于sevlet的一点尝试性解释
- Effective Java:创建和销毁对象
- 关于高可用的系统
- 转载-- python queue interpretation
- 数据读取器与指定的“LMSoft.Zhaopin.DAL.ArticleVote”不兼容。类型“ArticleMatcthId”的成员在同名的数据读取器中没有对应的列
- OCX控件ID对应关系的梳理
- 这多年来我一直在钻研的技术