定一个字符串可以使用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);
}

最新文章

  1. java 经典程序 100 例
  2. S Gallery – 很有特色的响应式 jQuery 相册插件
  3. 【Android】做一款类似我要当学霸里的学习监督的APP
  4. oracle审计详解-转
  5. 第十一篇 Integration Services:日志记录
  6. 移动端的touch事件处理
  7. winform 发布应用程序 提示 “未能注册模块(程序路径)\ieframe.dll”
  8. eclipse环境NDK问题汇总
  9. hdu 4869 Turn the pokers (2014多校联合第一场 I)
  10. 关于Lambda表达式访问外部变量
  11. 构建安全的Xml Web Service系列之如何察看SoapMessage
  12. spring boot / cloud (十七) 快速搭建注册中心和配置中心
  13. Asp.Net Core Identity+EFCore + Mysql踩坑记录
  14. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)
  15. JAVA实现网络文件下载
  16. Swift 学习- 08 -- 闭包
  17. mysql的 深度使用 - 游标 , 定时器, 触发器 的使用 ?
  18. Mybatis的mapper注册
  19. linux常用命令:ps 命令
  20. android_serialport_api hacking

热门文章

  1. Sparc V8
  2. spring cloud微服务快速教程之(十一) Sleuth(zipkin) 服务链路追踪
  3. c#音乐播放器
  4. pikachu-XXE(xml external entity-injection)
  5. 记录 2020年2月26日 java的一次远程技术面试
  6. mysql简单备份与恢复
  7. stlink 下载报错:Error Flash Download failed - &quot;Cortext-M0+&quot;
  8. 关于GC(垃圾回收)
  9. go语言开发工具sublime text3 + gosublime配置
  10. javascript单词