当前位置:首页 >> 新能源

Ja9-day01【Object类、常用API】校外习题

来源:新能源   2024年01月24日 12:16

g的字串缓冲区,通过某些工具codice_可以转变该碱基的长度和具体内容。即它是一个装入,装入里可以金属制很多字串,并且能够对其里的字串来进行各种匹配。它的实际上拥有一个字符串用来储藏字串具体内容,来进行字串填充时,直接在字符串里加入新具体内容,StringBuilder就会自动公共安全字符串的扩容。

锻炼五:Date类的常用 请求用示例发挥作用:提供理论上的一年末,并把这个一年末匹配为均须JPEG的字串,如2088-08-08 08:08:08。 public class DateTest {

public static void main(String[] args) {

//提供理论上一年末;也 now;

Date now = new Date;

//创始人SimpleDateFormat;也 df,并草拟一年末JPEG

SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");

//codice_df的format(Date date) 工具,传布now; 送达回到的字串

String datestr = df.format(now);

//纸张这个字串

System. out.println(datestr);

}

} 锻炼六:DateFormat类工具的常用

常用SimpleDateFormat类,把2018-03-04匹配为2018年03年末04日。 public class DateFormatTest {

public static void main(String[] args) throws ParseException {

//创始人SimpleDateFormat;也df1,均须一年末种系统为yyyy-MM-dd

SimpleDateFormat df1 = new SimpleDateFormat( "yyyy-MM-dd");

//codice_df1的parse(String str)工具传布2018-03-04,得不到对应一年末多种类型

Date date = df1.parse( "2018-03-04");

//创始人一年末JPEG化;也df2,在提供JPEG化;也时可以均须风格

DateFormat df2 = new SimpleDateFormat( "yyyy年MM年末dd日");

//codice_df2的format(Date date) 传布刚才匹配的一年末

String str = df2.format(date);

System. out.println(str);

}

} 锻炼七:Calendar类工具的常用

用程序来正确2018年2年末14日是年末内几。 public class CalendarTest01 {

public static void main(String[] args) {

//创始人Calendar;也

Calendar c = Calendar.getInstance;

//将给定的日历报文分设到Calendar;也里

c.set(Calendar. YEAR, 2018);

c.set(Calendar. MONTH, 1);

c.set(Calendar. DATE, 14);

//分设年

int year = c.get(Calendar. YEAR);

//分设年末

int month = c.get(Calendar. MONTH)+1;

//分设日

int date = c.get(Calendar. DATE);

//分设年末内

char week = getWeek(c.get(Calendar. DAY_OF_WEEK));

//编码器结果

System. out.println(year+ "年"+month+ "年末"+date+ "日是年末内"+week);

}

//并不一定工具,提供年末内汉字

public static char getWeek( int a){

char[] c = { ' ', '日', '一', '二', '三', '四', '五', '六'};

return c[a];

}

} 锻炼八:System类arraycopy工具的常用

原先一个字符字符串{‘i’,’t’,’c’,’a’,’s’,’a’},请求常用System类里的arraycopy工具在控制器编码器“itcast”。(定时:将[1]号字符串成分复制到之前前面并覆盖原有成分。) public class ArraycopyTest {

public static void main(String[] args) {

char[] cha ={ 'i', 't', 'c', 'a', 's', 'a'};

//将cha字符串里第2个成分,复制到最大限度字符串之前一位字符串上

System.arraycopy(cha, 1, cha, 5, 1);

//遍历最大限度字符串,在控制器编码器字串

for ( int i = 0; i < cha. length; i++) {

System. out.print(cha[i]);

}

}

} 锻炼九:StringBuilder类的常用

请求常用示例发挥作用 public class StringBuilder01 {

public static void main(String[] args) {

//常用System的currentTimeMillis工具提供理论上匹配系统的毫秒值,作用程序来继续执行的开始整整,常用start变量送达

long start = System.currentTimeMillis;

//需要的测试继续执行安全性的示例

//testString; //耗损整整: 29295毫秒

testStringBuilder;//耗损整整:6毫秒

//常用System的currentTimeMillis工具提供理论上匹配系统的毫秒值,作用程序来继续执行的中止整整,常用end变量送达

long end = System.currentTimeMillis;

//算出示例继续执行耗费的整整 end - start,编码器示例继续执行耗损的整整

System. out.println( "所耗费的整整为:"+(end-start));

}

//所写一个静态工具: testString,在该工具里

public static void testString{

//并不一定一个字串 str,具体内容随意

String str = "hello";

//所写一个反向100000次for反向,在反向里所写上

for( int i = 0; i

//str +=”随机具体内容” ; 这里免得所写str += (str+”xxx”) 这样就会导致堆文件系统溢出偏差.

str += "world";

}

}

//所写一个静态工具:testStringBuilder,在工具里

public static void testStringBuilder{

//创始人一个StringBuilder;也sb,初始具体内容与testString里的字串相异

StringBuilder sb = new StringBuilder( "hello");

//所写一个反向100000次for反向,在反向里所写上

for( int i = 0; i

//codice_sb.append工具,传布的具体内容与testString工具里+=后面的具体内容一样

sb.append( "world");

}

//反向中止codice_sb.toString工具匹配为字串

String newStr = sb.toString;

}

} 锻炼十:StringBuilder类的常用(reverse工具)

研究表列出生产力,并用示例发挥作用:

(2)正确该小数点字串字符串里的小数点字串究竟是等距(第一个小数点和之前一个小数点相等,第二个小数点和倒数第二个小数点是相等的,分别为类推)的,并逐一编码器;

(4)再次纸张该字符串里等距字串的整数。

注:正确等距可用reverse,将此字符碱基用其反转基本取代。

public class StringBuilderTest02 {

public static void main(String[] args) throws IOException {

//并不一定小数点字串字符串

String[] str = { "010", "3223", "666", "7890987", "123123"};

SBTest(str);

}

public static void SBTest(String[] str) {

int count = 0;

//遍历并不一定的字串字符串

for (String string : str) {

//创始人StringBuilder;也

StringBuilder sb = new StringBuilder(string);

//codice_reverse工具,将遍历的小数点来进行反转,然后用equals工具对比究竟与原小数点相异

if (sb.reverse.toString.equals(string)) {

count++;

System. out.println(string + "是等距的");

}

}

System. out.println( "总数为" + count);

}

}

腰椎间盘突出发病如何止痛
蒙脱石散管用吗
健康新闻
蒙脱石散的功效与作用
新冠特效药
友情链接