67,549
社区成员




public class SortTest {
public static void main(String[] args) {
Character[] c = { 'a', 's', 'd', 'A', 'f', 'h', 'F' };
double tempA;
double tempB;
char chA;
for (int i = 0; i < c.length; i++) {
for (int j = i + 1; j < c.length; j++) {
tempA = c[i] < 97 ? c[i] + 31.5 : c[i];
tempB = c[j] < 97 ? c[j] + 31.5 : c[j];
if (tempA > tempB) {
chA = c[i];
c[i] = c[j];
c[j] = chA;
}
}
}
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
}
}
import java.lang.*;
import java.util.*;
public class Test{
public static void main(String[] args){
String[] s = new String[]{"a","s","d","A","f","h","F"};
System.out.println(Arrays.toString(s));
//System.out.println((int)'a');
//System.out.println((int)'A');
//System.out.println((int)'z');
//System.out.println((int)'Z');
String [] s1 = new String[50];
for(int i=0;i<s.length;i++){
char c = getChar(s[i]);
System.out.println(c);
if(isUpper(c)){
//System.out.println(getUpperIndex(c));
s1[getUpperIndex(c)] = s[i];
}else{
//System.out.println(getLowIndex(c));
s1[getLowIndex(c)] = s[i];
}
}
System.out.println(Arrays.toString(s1));
copyArrayForNotNull(s1,s);
System.out.println(Arrays.toString(s));
}
//将String转成char并取得值
public static char getChar(String s){
return (s.charAt(0));
}
//取得大写char应该在数组中的位置 存放位置0,2,4...偶数位
public static int getUpperIndex(char c){
final int upperStart = 65;
final int upperEnd = 90;
int i = 2*((int)c-upperStart);
return i;
}
//取得小写char应该在数组中的位置 存放位置1,3,5...奇数位
public static int getLowIndex(char c){
final int lowStart = 97;
final int lowEnd = 122;
int i = 2*((int)c-lowStart)+1;
return i;
}
//判断是否为大写
public static boolean isUpper(char c){
final int upperStart = 65;
final int upperEnd = 90;
final int lowStart = 97;
final int lowEnd = 122;
if((int)c>=upperStart && (int)c<=upperEnd){
return true;
}else{
return false;
}
}
//将数组s1中的非空元素拷贝到s2
public static boolean copyArrayForNotNull(String[] s1,String[] s2){
int s2Index = 0;
try{
for(int i=0;i<s1.length;i++){
if(s1[i]!=null){
s2[s2Index] = s1[i];
}else{
continue;
}
s2Index++;
}
}catch(Exception e){
System.out.println("数组拷贝错误,错误原因:"+e.toString());
return false;
}
return true;
}
}
public class Sort {
public static void main(String[] args)
{
char a[]={'g','s','A','a','U','K','e','k'};
int l=a.length;
char temp;
int j;
int n=l-1;
for(int i=0;i<l;i++)
{
for(j=0;j<n;j++)
{
//System.out.print(" "+(j+1));
if(Character.toUpperCase(a[j])>=Character.toUpperCase(a[j+1]))
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
n--;
}
for(int k=0;k<l-1;k++)
{
if(Character.toUpperCase(a[k])==Character.toUpperCase(a[k+1]))
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
}
}
for(int k=0;k<l;k++)
{
System.out.print(" "+a[k]);
}
}
}