早教吧作业答案频道 -->其他-->
java程序,假设s1,s2,s3和s4是四个字符串引用,分别对它们进行如下赋值:Strings1="Welcometojava";Strings2=s1;Strings3=newString("Welcometojava");Strings4=s3.intern();分析并写出下列表达式的结果,然后编程验
题目详情
java程序,假设s1,s2,s3和s4是四个字符串引用,分别对它们进行如下赋值:
String s1="Welcome to java";
String s2=s1;
String s3=new String("Welcome to java");
String s4=s3.intern();
分析并写出下列表达式的结果,然后编程验证你的分析.
(1)s1=s2 (13)s1.length()
(2)s2=s3 (14)s1.subString(5)
(3)s1.equals(s2) (15)s1.SubString(5,11)
(4)s2.equals(s3) (16)s1.startsWith("wel")
(5)s1.compareTo(s2) (17)s1.endsWith("java")
(6)s2.compareTo(s3) (18)s1.toLowerCase()
(7)s1==s4 (19)s1.toUpperCase()
(8)s1.charAt(0) (20)" Welcome ".trim()
(9)s1.indexOf('j') (21)s1.replace('o','T')
(10)s1.indexOf('to') (22)s1.replaceAll("o","T")
(11)s1.lastindexOf('j') (23)s1.replaceFirst("o","T")
(12)s1.lastindexOf("o",15) (24)s1.toCharArray()
String s1="Welcome to java";
String s2=s1;
String s3=new String("Welcome to java");
String s4=s3.intern();
分析并写出下列表达式的结果,然后编程验证你的分析.
(1)s1=s2 (13)s1.length()
(2)s2=s3 (14)s1.subString(5)
(3)s1.equals(s2) (15)s1.SubString(5,11)
(4)s2.equals(s3) (16)s1.startsWith("wel")
(5)s1.compareTo(s2) (17)s1.endsWith("java")
(6)s2.compareTo(s3) (18)s1.toLowerCase()
(7)s1==s4 (19)s1.toUpperCase()
(8)s1.charAt(0) (20)" Welcome ".trim()
(9)s1.indexOf('j') (21)s1.replace('o','T')
(10)s1.indexOf('to') (22)s1.replaceAll("o","T")
(11)s1.lastindexOf('j') (23)s1.replaceFirst("o","T")
(12)s1.lastindexOf("o",15) (24)s1.toCharArray()
▼优质解答
答案和解析
public class Test {
public static void main(String[] args) {
String s1="Welcome to java";
String s2=s1;
String s3=new String("Welcome to java");
String s4=s3.intern();
System.out.println("s1=s2:" + (s1==s2));
System.out.println("s2=s3:" + (s2==s3));
System.out.println("s1.equals(s2):" + s1.equals(s2));
System.out.println("s2.equals(s3):" + s2.equals(s3));
System.out.println("s1.compareTo(s2):" + s1.compareTo(s2));
System.out.println("s2.compareTo(s3) :" + s2.compareTo(s3));
System.out.println("s1==s4:" + (s1==s4));
System.out.println("s1.charAt(0) :" + s1.charAt(0) );
System.out.println("s1.indexOf('j') :" + s1.indexOf('j') );
System.out.println("s1.indexOf('to'):" + s1.indexOf("to"));
System.out.println("s1.lastindexOf('j') :" + s1.lastIndexOf("j"));
System.out.println("s1.lastindexOf(\"o\",15):" + s1.lastIndexOf("o",15));
System.out.println("s1.length():" + s1.length());
System.out.println("s1.subString(5):" + s1.substring(5));
System.out.println("s1.SubString(5,11):" + s1.substring(5,11));
System.out.println("s1.startsWith(\"wel\"):" + s1.startsWith("wel"));
System.out.println("s1.endsWith(\"java\"):" + s1.endsWith("java"));
System.out.println("s1.toLowerCase():" + s1.toLowerCase());
System.out.println("s1.toUpperCase():" + s1.toUpperCase());
System.out.println("\" Welcome \".trim():" + " Welcome ".trim());
System.out.println("s1.replace('o','T'):" + s1.replace('o','T'));
System.out.println("s1.replaceAll(\"o\",\"T\"):" + s1.replaceAll("o","T"));
System.out.println("s1.replaceFirst(\"o\",\"T\"):" + s1.replaceFirst("o","T"));
System.out.println("s1.toCharArray():" + s1.toCharArray());
}
}
public static void main(String[] args) {
String s1="Welcome to java";
String s2=s1;
String s3=new String("Welcome to java");
String s4=s3.intern();
System.out.println("s1=s2:" + (s1==s2));
System.out.println("s2=s3:" + (s2==s3));
System.out.println("s1.equals(s2):" + s1.equals(s2));
System.out.println("s2.equals(s3):" + s2.equals(s3));
System.out.println("s1.compareTo(s2):" + s1.compareTo(s2));
System.out.println("s2.compareTo(s3) :" + s2.compareTo(s3));
System.out.println("s1==s4:" + (s1==s4));
System.out.println("s1.charAt(0) :" + s1.charAt(0) );
System.out.println("s1.indexOf('j') :" + s1.indexOf('j') );
System.out.println("s1.indexOf('to'):" + s1.indexOf("to"));
System.out.println("s1.lastindexOf('j') :" + s1.lastIndexOf("j"));
System.out.println("s1.lastindexOf(\"o\",15):" + s1.lastIndexOf("o",15));
System.out.println("s1.length():" + s1.length());
System.out.println("s1.subString(5):" + s1.substring(5));
System.out.println("s1.SubString(5,11):" + s1.substring(5,11));
System.out.println("s1.startsWith(\"wel\"):" + s1.startsWith("wel"));
System.out.println("s1.endsWith(\"java\"):" + s1.endsWith("java"));
System.out.println("s1.toLowerCase():" + s1.toLowerCase());
System.out.println("s1.toUpperCase():" + s1.toUpperCase());
System.out.println("\" Welcome \".trim():" + " Welcome ".trim());
System.out.println("s1.replace('o','T'):" + s1.replace('o','T'));
System.out.println("s1.replaceAll(\"o\",\"T\"):" + s1.replaceAll("o","T"));
System.out.println("s1.replaceFirst(\"o\",\"T\"):" + s1.replaceFirst("o","T"));
System.out.println("s1.toCharArray():" + s1.toCharArray());
}
}
看了 java程序,假设s1,s2...的网友还看了以下:
如图1所示是小明用红磷在空气中燃烧的方法测定空气的成分.实验过程如下:第一步:将集气瓶容积划分为五 2020-05-02 …
作业调度,其主要功能是根据一定的算法,从输人的一批作业中选出若干个作业,分配必要的资源,如内存、外设 2020-05-31 …
实验室用硫酸铝酸性溶液制备可溶性的碱式硫酸铝[Ala(SO4)b(OH)c],并用它对烟气进行脱硫 2020-06-27 …
①A※B=A×B-A-1,已知2※(X※2)=0,求X.请不用方程列式,并写出意思.②如果2※4= 2020-06-27 …
用两个相同的小量程电流表,分别改装成了两个量程不同的大量程电流表A1、A2,若把A1、A2分别采用 2020-07-08 …
生物--现代生物科技专题设计并生产更加符合人类需要的蛋白质具有极为广阔的应用前景.利用胚胎工程技术 2020-07-29 …
方程应用题1、“移项”、“合并”、“系数化为1”都是将一个比较复杂的一元一次方程如2x-19=7x 2020-08-02 …
比较函数大小要过程如用啥诱导公式在啥单调间.cos15/8*π与cos14/9*π;cos515° 2020-08-02 …
编写一个程序,用于进行集合的并、差和交运算.例如输入整数集合{954367}和{2469},计算出 2020-08-02 …
一架飞机的飞行时间和航程如下表:飞行时间/时2569航程/Km14603650438065701.表 2020-11-10 …