Javase day07_ String

String

@Test
	public void myTest06(){
		//给String 类型的变量赋值打的方式有两种
		//静态赋值时,放到常量池中,如果字符串的值相同,==比时为true
		//new方式创建时,无论字符串值是否相同,都会新生成一个对象 ==比较久为false
		String s1="123";
		String s2="123";
		String s3=new String("456");
		String s4=new String("456");
		//String重写了equals方法,equals比较里面的文字是否相同
		if(s1.equals(s2)){
			System.out.println("相同");
			}
		else{
			System.out.println("不相同");
		}
		if(s3.equals(s4)){
			System.out.println("相同");
			}
		else{
			System.out.println("不相同");
		}
		if(s1==s2){
			System.out.println("相同");
			}
		else{
			System.out.println("不相同");
		}
		if(s3==s4){
			System.out.println("相同");
			}
		else{
			System.out.println("不相同");
		}
	}
@Test
    public void test4(){
        System.out.println(5+6+'A');//76
        System.out.println(5+6+"A");//11A
        System.out.println(5+"A"+6);//5A6
    }
  @Test
	public void test5(){
    System.out.println(5+6+'A');//76
    System.out.println(5+6+"A"+6+5);//11A65
    System.out.println(5+"A"+6+5);//5A65
}
  //equals
  //e
  @Test
 	public void test6(){
	  String s="s123fbg";
	  boolean result=s.equals("admin");
	  System.out.println(result);
	  String s1="Admin";
	  boolean result1=s1.equalsIgnoreCase("admin");
	  System.out.println(result1);
	  //判断邮箱
	  //yunjiaen@neusoft.com
	  //1.不能为空
	  //2.不能@.开头
	  //3.不能以.@结尾
	  //4.里面只能有一个@
	  //5.@符必须在.之前 
  }
  @Test
	public void test7(){
	  System.out.println("请输入一个邮箱");
	  Scanner sc=new Scanner(System.in);
		String email=sc.next();
		if(email.length()==0)
			 //1.不能为空
			System.out.println("不能为空");
		else {
			 //2.不能以@.开头
			if(email.startsWith("@"))
			{
				System.out.println("不能以@开头");
			}
			if(email.startsWith("."))
			{
				System.out.println("不能以.开头");
			}
			 //3.不能以@.结尾
			if(email.endsWith("@"))
			{
				System.out.println("不能以@结尾");
			}
			if(email.endsWith("."))
			{
				System.out.println("不能以.结尾");
			}
			 //4.里面只能有一个@
			if(email.indexOf("@")<0)//email.indexOf("@") @第一个出现的位置
			{
				System.out.println("必须有@");
			}
			if(email.indexOf(".")<0)
			{
				System.out.println("必须有.");
			}
			if(email.indexOf("@")!=email.lastIndexOf("@"))//email.lastIndexOf("@") @最后出现的位置
			{
				System.out.println("只能有一个@");
			}
			if(email.indexOf(".")!=email.lastIndexOf("."))
			{
				System.out.println("只能有一个.");
			}
			 //5.@必须在.之前
			if(email.indexOf("@")==email.lastIndexOf("@")&&email.indexOf(".")==email.lastIndexOf("."))
			{
				if(email.indexOf("@")>email.indexOf("."))
				{
					System.out.println("@必须在.之前");
				}
			}
			
  }
  }
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值