一段Java代码不太明白~~~请高手详解一下~~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/25 13:21:07
public class B2
{
public static void main( String args[] )
{
String s1 = "hello there";
char charArray[] = new char[ 5 ];

System.out.printf( "s1: %s", s1 );

for ( int count = s1.length() - 1; count >= 0; count-- )
System.out.printf( "%s ", s1.charAt( count ) );

// copy characters from string into charArray
s1.getChars( 0, 5, charArray, 0 );
System.out.print( "\nThe character array is: " );

for ( char character : charArray )
System.out.print( character );
}
}

public class B2 {
public static void main(String args[]) {
String s1 = "hello there";//定义s1
char charArray[] = new char[5];//定义charArray是一个数组

System.out.printf("s1: %s", s1);//输出s1:+s1

for (int count = s1.length() - 1; count >= 0; count--)//遍历
System.out.printf("%s ", s1.charAt(count));//输出每一个

// copy characters from string into charArray
s1.getChars(0, 5, charArray, 0);//把s1前五个考到charArray里
System.out.print("\nThe character array is: ");//输出

for (char character : charArray)//遍历
System.out.print(character);//输出
}
}

class B2
{
public static void main( String args[] )
{
String s1 = "hello there";
char charArray[] = new char[ 5 ];

System.out.printf( "s1: %s", s1 ); //你 加个回车看就明白了
System.out.printf("\n");

for ( int count = s1.length(