• 字符串习题


    public class Test
    {
    	public static void main(String args[])
    	{
    		String s1 = "This is a dog";
    		String s2 = s1;
    		String s3 = "this is a dog";
    		String s4 = "This is a dog";
    		System.out.println("s1.equals(s2):" + s1.equals(s2));
    		System.out.println("s1.compareTo(s2):" + s1.compareTo(s2));
    		System.out.println("s1.equals(s4):" + s1.equals(s4));
    		System.out.println("s1.compareTo(s4):" + s1.compareTo(s4));
    		System.out.println("s1.equals(s3):" + s1.equals(s3));
    		System.out.println("s1.compareTo(s3):" + s1.compareTo(s3));	
    		/*
    			---------- 运行 ----------
    			s1.equals(s2):true
    			s1.compareTo(s2):0
    			s1.equals(s4):true
    			s1.compareTo(s4):0
    			s1.equals(s3):false
    			s1.compareTo(s3):-32
    			输出完成 (耗时 0 秒) - 正常终止
    		*/
    	}
    }

    public class Test
    {
    	public static void main(String args[])
    	{
    		String s1 = "This ";
    		String s2 = "is ";
    		String s3 = "a ";
    		String s4 = "String";
    		String sConcat = s1.concat(s2).concat(s3).concat(s4);
    		System.out.println(sConcat);
    		/*
    				---------- 运行 ----------
    			This is a String
    
    			输出完成 (耗时 0 秒) - 正常终止		
    		*/
    	}
    }


    	public static void main(String args[])
    	{
    		String s1 = "This ";
    		String s2 = "is ";
    		String s3 = "a ";
    		String s4 = "String";
    		String sConcat = s1.concat(s2).concat(s3).concat(s4);
    		String sCopy = String.copyValueOf(s1.toCharArray());
    		System.out.println("concat:" + sConcat + "
    copyValueOf:" + sCopy);
    		/*
    			---------- 运行 ----------
    			concat:This is a String
    			copyValueOf:This 
    
    			输出完成 (耗时 0 秒) - 正常终止
    		*/
    	}


  • 相关阅读:
    实现 AD 采样,使用 LCD1602 显示 AD 数值
    数据结构(C语言)—排序
    Keil uVision4 创建51单片机工程
    51单片机 方波
    51单片机串口中断实验
    51单片机 中断控制蜂鸣器
    串口通信
    定时器与计数器
    中断系统
    《web前端设计基础——HTML5、CSS3、JavaScript》 张树明版 简答题简单整理
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/4258553.html
Copyright © 2020-2023  润新知