2024-01-05 16:39来源:m.sf1369.com作者:宇宇
import java.util.Arrays;
import java.util.Random;
public class Test {
public static void main(String[] args) {
int array[] = {1,4,5,3,2,0};
//没有排序前的输出
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]);
}
System.out.println();
Arrays.sort(array);//进行排序
//排序后的输出
for(int j = 0; j< array.length; j++){
System.out.print(array[j]);
}
}
}
这样条件就都满足了,需要改进可以给我发消息。
Console.WriteLine(请输入:);
string str = Console.ReadLine();
if (str.Length < 4)
{
Console.WriteLine(请输入长度大于3字符串!请重试..);
GetString();
}
else
{
Console.WriteLine(接收到的字符串: + str.ToString() + ;长度为: + str.Length.ToString());
Console.WriteLine(第一个出现字母a的位置: + str.IndexOf(a).ToString());
Console.WriteLine(第三个字符后面插入子串“hello”后: + str.Insert(3, hello).ToString());
Console.WriteLine(把“hello”替换成“me”后: + str.Replace(hello, me).ToString());
string[] arr = str.Split(new char[] { 'm' });
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(分离后的[ + i.ToString() + ]字符串: + arr[i].ToString());
}
}
String str= new String(I am tomato);
byte[] b = new byte[str.length()];
for(int i=0; i
import java.util.*;
public class TestComparable {
public static void main(String[] args) {
List s = new ArrayList();
s.add(new Name(wang,fei));
s.add(new Name(wang,hong));
s.add(new Name(yang,lin));
s.add(new Name(li,ju));
s.add(new Name(liu,feng));
Collections.sort(s);
System.out.println(s);
}
}
class Name implements Comparable {
String firstName;
String lastName;
Name(String firstName,String lastName) {
this.firstName=firstName;
this.lastName=lastName;
}
public boolean equals(Object obj) {
if(obj instanceof Name) {
Name n = (Name)obj;
return (firstName.equals(n.firstName))&& (lastName.equals(n.lastName)) ;
}
return super.equals(obj);
}
public int compareTo(Object obj) {
Name nn = (Name)obj;
int last=lastName.compareTo(nn.lastName);
int first=firstName.compareTo(nn.firstName);
return (first!=0 ? first : last) ;
}
public String toString() {
return firstName+ +lastName;
}
}