work018.java
package test01;
public class work018
{
public static void main(String[] args)
{
String str1 = "";
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10000; i++)
{
str1 = str1 + i;
}
long endTime = System.currentTimeMillis();
long time = endTime - startTime;
System.out.println("String消耗时间:" + time);
StringBuilder builder = new StringBuilder("");
long startTime2 = System.currentTimeMillis();
for (int j = 0; j < 10000; j++)
{
builder.append(j);
}
long endTime2 = System.currentTimeMillis();
long time2 = endTime2 - startTime2;
System.out.println("StringBuilder消耗时间:" + time2);
StringBuilder builder2 = new StringBuilder("hello");
builder2.insert(5, " world");
System.out.println(builder2.toString());
StringBuilder builder3 = new StringBuilder("abcdefghijklmnopqrstuvwxyz");
builder3.delete(4, 25);
System.out.println(builder3.toString());
}
}
work019.java
package test01;
public class work019
{
public static void main(String[] args)
{
//
String str1 = "Where are you come from";
String str2 = str1.toUpperCase();
String str3 = str2.toLowerCase();
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
//
String str4 = "I have money";
String str5 = "you have money";
String str6 = str4.substring(7, 12);
String str7 = str5.substring(9);
System.out.println(str4);
System.out.println(str5);
System.out.println(str6);
System.out.println(str7);
if(str6.equalsIgnoreCase(str7))
{
System.out.println("两个子串相同");
}
else
{
System.out.println("两个子串不相同");
}
//
String str8 = "13830008001";
String regString = "\\d{11}";
if (str8.matches(regString))
{
System.out.println(str8 + "是合法的手机号码");
}
String str9 = "13909005002";
String regString2 = "^1[3-9]\\d{9}$"; //^开始位置,$结束位置
if (str9.matches(regString2))
{
System.out.println(str9 + "是合法的手机号码");
}
//
StringBuilder builder = new StringBuilder();
for (int j = 0; j < 10; j++)
{
builder.append(j);
}
System.out.println(builder.toString());
}
}
work020.java
package test01;
public class work020
{
public static void main(String[] args)
{
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++)
{
arr[i] = i + 1;
System.out.print(arr[i]);
}
System.out.println();
int arr2[] = new int[5];
for (int j = 0; j < arr2.length; j++)
{
arr2[j] = j + 1;
System.out.print(arr2[j]);
}
System.out.println();
int[] arr3 = {1,2,3,4,5};
for (int k = 0; k < arr3.length; k++)
{
System.out.print(arr3[k]);
}
System.out.println();
int[] day = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
for (int m = 0; m < day.length; m++)
{
System.out.println((m + 1) + "月有" +day[m] + "天");
}
}
}
work021.java
package test02;
public class work021
{
public static void main(String[] args)
{
int myArr[][];
myArr = new int[2][4];
myArr[0][1] = 11;
int myArr1[][] = new int[2][];
myArr1[0] = new int[2];
myArr1[1] = new int[3];
myArr1[0][1] = 11;
myArr1[1][2] = 22;
int myArr2[][] = {{12,0},{45,10}};
System.out.println(myArr2[1][0]);
int a[][] = new int[3][4];
for (int i = 0; i < a.length; i++)
{
for (int j = 0; j < a[i].length; j++)
{
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}