小白的java学习之路 “ 字符串”
2024-09-06 21:03:19
定一个字符串可以使用string类和stringbuffer类。
string类提供了大量的操作字符串的方法,常用的如下:
获得字符串的长度: length()。
比较字符串:equals()。
链接字符串:concat()。
提取字符串:substring()。
搜索字符串:indexOf()。
拆分字符串:spilt()。
常用的stringbuffer类提供的方法如下:
转换成string类型:tostring()。
链接字符串:append()。
插入字符串:intsert()。
一些案例:
public class Demo_1 { public static void main(String[] args) {
// TODO Auto-generated method stub
String pwd;
@SuppressWarnings("resource")
Scanner input =new Scanner(System.in);
do{
System.out.println("请输入用户名:");
String name = input.next();
System.out.println("请输入密码:");
pwd= input.next();
if(pwd.length()<){
System.out.println("密码长度不够");
}else{
System.out.println("输入正确");
System.out.println("欢迎你!"+name);
break;
}
}while(pwd.length()!=);
}
boolean flag ;
public void panduan(String sfz , String sjh,String zj) {
flag=false;
int index=sjh.lastIndexOf("-"); if(!(sfz.length()==||sfz.length()==)){
System.out.println("身份证号必须是16位或18位!");
}
else if(sjh.length()<){
System.out.println("手机号必须是11位!");
}else if (index!=-&&index!=&&index!=&&zj.length()!=) {
System.out.println("座机号码区必须为4位,电话号码必须是7位!");
}else{
System.out.println("注册成功");
flag=true;
} } 调用:
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner input=new Scanner(System.in);
Practice2 pd =new Practice2();
do {
System.out.println("请输入身份证:");
String sfz = input.next();
System.out.println("请输入手机号码:");
String sjh = input.next();
System.out.println("请输入座机号:");
String zj = input.next();
pd.panduan(sfz, sjh, zj);
} while (pd.flag==false);
}
最新文章
- java 经典程序 100 例
- S Gallery – 很有特色的响应式 jQuery 相册插件
- 【Android】做一款类似我要当学霸里的学习监督的APP
- oracle审计详解-转
- 第十一篇 Integration Services:日志记录
- 移动端的touch事件处理
- winform 发布应用程序 提示 “未能注册模块(程序路径)\ieframe.dll”
- eclipse环境NDK问题汇总
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
- 关于Lambda表达式访问外部变量
- 构建安全的Xml Web Service系列之如何察看SoapMessage
- spring boot / cloud (十七) 快速搭建注册中心和配置中心
- Asp.Net Core Identity+EFCore + Mysql踩坑记录
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)
- JAVA实现网络文件下载
- Swift 学习- 08 -- 闭包
- mysql的 深度使用 - 游标 , 定时器, 触发器 的使用 ?
- Mybatis的mapper注册
- linux常用命令:ps 命令
- android_serialport_api hacking
热门文章
- Sparc V8
- spring cloud微服务快速教程之(十一) Sleuth(zipkin) 服务链路追踪
- c#音乐播放器
- pikachu-XXE(xml external entity-injection)
- 记录 2020年2月26日 java的一次远程技术面试
- mysql简单备份与恢复
- stlink 下载报错:Error Flash Download failed - ";Cortext-M0+";
- 关于GC(垃圾回收)
- go语言开发工具sublime text3 + gosublime配置
- javascript单词