String
@Test
public void myTest06(){
String s1="123";
String s2="123";
String s3=new String("456");
String s4=new String("456");
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');
System.out.println(5+6+"A");
System.out.println(5+"A"+6);
}
@Test
public void test5(){
System.out.println(5+6+'A');
System.out.println(5+6+"A"+6+5);
System.out.println(5+"A"+6+5);
}
@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);
}
@Test
public void test7(){
System.out.println("请输入一个邮箱");
Scanner sc=new Scanner(System.in);
String email=sc.next();
if(email.length()==0)
System.out.println("不能为空");
else {
if(email.startsWith("@"))
{
System.out.println("不能以@开头");
}
if(email.startsWith("."))
{
System.out.println("不能以.开头");
}
if(email.endsWith("@"))
{
System.out.println("不能以@结尾");
}
if(email.endsWith("."))
{
System.out.println("不能以.结尾");
}
if(email.indexOf("@")<0)
{
System.out.println("必须有@");
}
if(email.indexOf(".")<0)
{
System.out.println("必须有.");
}
if(email.indexOf("@")!=email.lastIndexOf("@"))
{
System.out.println("只能有一个@");
}
if(email.indexOf(".")!=email.lastIndexOf("."))
{
System.out.println("只能有一个.");
}
if(email.indexOf("@")==email.lastIndexOf("@")&&email.indexOf(".")==email.lastIndexOf("."))
{
if(email.indexOf("@")>email.indexOf("."))
{
System.out.println("@必须在.之前");
}
}
}
}
}