zoukankan      html  css  js  c++  java
  • 看结果,测试?java中的String类 字符串拆分成字符串数组 判定邮箱地址 字符串比较 参数传递?

    看结果1?

    package com.swift;
    
    class ArrayString {
        public static void main(String[] args) {
            String str = "swift:30|sunny:28|Ben:32";
            String str1[] = str.split("\|");
            for (int i = 0; i <= str1.length - 1; i++) {
                String str2[] = str1[i].split("\:");
    
                System.out.println("名字是" + str2[0] + "-->" + "年龄是" + str2[1]);
                System.out.println();
    
            }
        }
    }

    看结果2?

    package com.swift;
    
    class StringEmail 
    {
        public static void main(String[] args) 
        {
            String email="tiankong_0000@sina.com.cn";
            String email1="81257211@qq.com";
            String email2="tiankong.sina.com";
            String email3="81257211@sina";
            String email4="qq.com@81257211";
            String email5="@.";
            System.out.println(operate(email));
            System.out.println(operate(email1));
            System.out.println(operate(email2));
            System.out.println(operate(email3));
            System.out.println(operate(email4));
            System.out.println(operate(email5));
            
        }
        public static boolean operate(String str)
        {
             boolean flag=true;
             if (str.indexOf("@")==-1)
             {
                 flag=false;
             }
             if (str.indexOf(".")==-1)
             {
                 flag=false;
             }
             if (str.indexOf(".")<=str.indexOf("@"))
             {
                 flag=false;
             }
             return flag;
        }
    
    }

    看结果3?

    package com.swift;
    
    class StringEquals 
    {
        public static void main(String[] args) 
        {
            String str="Hello";
            String str1=new String("Hello");
            if(str.equals(str1))
            System.out.println("111111111");
            else
            System.out.println("00000000000");
        }
    }

    看结果4?

    package com.swift;
    
    public class StringResult {
        String str = new String("good");
        char[] ch = { 'a', 'b', 'c' };
    
        public static void main(String args[]) {
            StringResult sr = new StringResult();
            sr.change(sr.str, sr.ch);
            System.out.print(sr.str + "and");
            System.out.print(sr.ch);
        }
    
        public void change(String str, char ch[]) {
            str = "test ok";
            ch[0] = 'g';
        }
    }

    看结果5?

    package com.swift;
    
    class StringJudge 
    {
        public static void main(String[] args) 
        {
            String str1="Hello";
            String str2=new String(" World");
            System.out.println(str1+str2);
            String a="ok";
            String b="ok";
            String c=new String ("ok");
            if(a==b)
                System.out.println("1");
            else
                System.out.println("0");
            if(a==c)
                System.out.println("1");
            else
                System.out.println("0");
            if(b==c)
                System.out.println("1");
            else
                System.out.println("0");
            
            if(a.equals(b))
                System.out.println("1");
            else
                System.out.println("0");
            if(a.equals(c))
                System.out.println("1");
            else
                System.out.println("0");
            if(b.equals(c))
                System.out.println("1");
            else
                System.out.println("0");
        }
    }

    如何解释?

    不同的是,第一条先在内存中创建了"ok"这个String,然后将reference赋给a,下一条语句String b = "ok";那么JVM将不再创建"ok",而是直接将第一个"ok"的reference赋给b,也就是说,a和b是使用同一块内存,而String c = new String("ok");那JVM将在内存中再创建一块区域放上“ok”这个字符串。

     看结果6?

    package com.swift;

      public class Emp {
        int x=10;
      }

    public class ParameterTest {
        public static void main(String[] args) {
            Emp d = new Emp();
            d.x = 30;
            fun(d);
            System.out.println(d.x);
        }
    
        public static void fun(Emp example) {
            example.x = 100;
        }
    
    }

    看结果7?

    package com.swift;
    
    public class ParameterTest {
        public static void main(String[] args) {
            String str="Hello";
            fun(str);
            System.out.println(str);
        }
    
        public static void fun(String temp)
        {
            temp="World";
        }
    
    }

    看结果8?

    class Emp
    {
        String x="swift";
    }
    class Chuandi
    {
        public static void main(String[] args) 
        {
            Emp d=new Emp();
            d.x="who";
            fun(d);
            System.out.println(d.x);
        }
        public static void fun(emp example)
        {
            example.x="is";
        }
    }
  • 相关阅读:
    C#类中的字段、属性和方法
    Linux下制作Windows启动U盘的工具
    将samba共享目录映射为本地文件夹(百度网盘直接下载到samba共享目录下)
    《怎样编写研究报告》读书笔记0-0
    mcnp的重复探测器单元计数-fmesh卡的介绍
    单能X射线产生方法
    matlab学习之降噪平滑算法
    matlab学习之求解函数的根和极小值
    matlab学习之绘制参数曲线,添加辅助线以及颜色设置
    MC资源整理
  • 原文地址:https://www.cnblogs.com/qingyundian/p/7800831.html
Copyright © 2011-2022 走看看