zookeeper python接口实例详解
306
2022-11-22
java Arrays快速打印数组的数据元素列表案例
1、Arrays.toString
用来快速打印一维数组的数据元素列表
2、Arrays.deepToString 快速打印一个二维数组的数据元素列表
public static strictfp void main(String[] args) {
String[][] arr = {{"aaa","bbb"},{"ccc"}};
for(int x=0;x for(int y=0;y System.out.println(arr[x][y]); } } //Arrays.deepToString 快速打印一个二维数组的数据元素列表 System.out.println(Arrays.deepToString(arr)); } 补充知识:java使用快速排序法对数组从小到大排序 给定值的快速排序` import java.util.*; public class Program_kuaipai { public static void main(String[] args) { String str = "12 34 1 -5 9 100 55 0"; String[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 System.out.println(Arrays.toString(numArray));//用Arrays.thttp://oString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” //int sentry=numArray[(i+j)/2]; while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
for(int y=0;y System.out.println(arr[x][y]); } } //Arrays.deepToString 快速打印一个二维数组的数据元素列表 System.out.println(Arrays.deepToString(arr)); } 补充知识:java使用快速排序法对数组从小到大排序 给定值的快速排序` import java.util.*; public class Program_kuaipai { public static void main(String[] args) { String str = "12 34 1 -5 9 100 55 0"; String[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 System.out.println(Arrays.toString(numArray));//用Arrays.thttp://oString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” //int sentry=numArray[(i+j)/2]; while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
System.out.println(arr[x][y]);
}
}
//Arrays.deepToString 快速打印一个二维数组的数据元素列表
System.out.println(Arrays.deepToString(arr));
}
补充知识:java使用快速排序法对数组从小到大排序
给定值的快速排序`
import java.util.*;
public class Program_kuaipai
{
public static void main(String[] args)
{
String str = "12 34 1 -5 9 100 55 0";
String[] numStrs = str.split(" ");
int[] numArray = new int[numStrs.length];
for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 System.out.println(Arrays.toString(numArray));//用Arrays.thttp://oString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” //int sentry=numArray[(i+j)/2]; while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
numArray[i] = Integer.valueOf(numStrs[i]);
}
quickSort(numArray);//快速排序
/*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 System.out.println(Arrays.toString(numArray));//用Arrays.thttp://oString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” //int sentry=numArray[(i+j)/2]; while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
System.out.println(numArray[i]);
}*///用for循环输出整形数组
System.out.println(Arrays.toString(numArray));//用Arrays.thttp://oString()输出
}
public static void quickSort(int[] numArray)
{
if(numArray.length>0)
{
quickSort(numArray,0,numArray.length-1);
}
}
private static void quickSort(int[] numArray,int left,int right)
{
if(left>right)
{
return;
}
int i=left;
int j=right;
int sentry=numArray[left];//找一个“哨兵”
//int sentry=numArray[(i+j)/2];
while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
while(i
{
j--;
}
while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
i++;
}
if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } } 可输入值的快速排序: import java.util.*; public class Program_kuaipai { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine();//输入需要排序的数字 StrikNjEQPnZgxng[] numStrs = str.split(" "); int[] numArray = new int[numStrs.length]; for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
int mid=numArray[i];
numArray[i]=numArray[j];
numArray[j]=mid;
}
}
int mid=numArray[i];
numArray[i]=numArray[left];
numArray[left]=mid;//改变“哨兵”的位置
quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排
quickSort(numArray, i+1, right );//递归,将右部分再次进行快排
}
}
可输入值的快速排序:
import java.util.*;
public class Program_kuaipai
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();//输入需要排序的数字
StrikNjEQPnZgxng[] numStrs = str.split(" ");
int[] numArray = new int[numStrs.length];
for(int i=0;i { numArray[i] = Integer.valueOf(numStrs[i]); } quickSort(numArray);//快速排序 /*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
numArray[i] = Integer.valueOf(numStrs[i]);
}
quickSort(numArray);//快速排序
/*for(int i=0;i { System.out.println(numArray[i]); }*///用for循环输出整形数组 //Arrays.sort(numArray);//用Arrays.sort()的排序 System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出 } public static void quickSort(int[] numArray) { if(numArray.length>0) { quickSort(numArray,0,numArray.length-1); } } private static void quickSort(int[] numArray,int left,int right) { if(left>right) { return; } int i=left; int j=right; int sentry=numArray[left];//找一个“哨兵” while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
System.out.println(numArray[i]);
}*///用for循环输出整形数组
//Arrays.sort(numArray);//用Arrays.sort()的排序
System.out.println(Arrays.toString(numArray));//用Arrays.toString()输出
}
public static void quickSort(int[] numArray)
{
if(numArray.length>0)
{
quickSort(numArray,0,numArray.length-1);
}
}
private static void quickSort(int[] numArray,int left,int right)
{
if(left>right)
{
return;
}
int i=left;
int j=right;
int sentry=numArray[left];//找一个“哨兵”
while(i { while(i { j--; } while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
while(i
{
j--;
}
while(i { i++; } if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
i++;
}
if(i { int mid=numArray[i]; numArray[i]=numArray[j]; numArray[j]=mid; } } int mid=numArray[i]; numArray[i]=numArray[left]; numArray[left]=mid;//改变“哨兵”的位置 quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排 quickSort(numArray, i+1, right );//递归,将右部分再次进行快排 } }
{
int mid=numArray[i];
numArray[i]=numArray[j];
numArray[j]=mid;
}
}
int mid=numArray[i];
numArray[i]=numArray[left];
numArray[left]=mid;//改变“哨兵”的位置
quickSort(numArray, left, i-1 );//递归,将左部分再次进行快排
quickSort(numArray, i+1, right );//递归,将右部分再次进行快排
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~