public class Tests {
public static String[] ListArr(int[] arr1,int[] arr2) {
String[] result
String str1=""
String str2=""
int str3=0
for(int i=0i<arr1.lengthi++) {
str1=str1+arr1[i]
}
for(int i=0i<arr2.lengthi++) {
str2=str2+arr2[i]
}
str3=Integer.parseInt(str1)+Integer.parseInt(str2)
System.out.println(str3)
String str= Integer.toString(str3)
result = new String[str.length()]
for(int i=0i<result.lengthi++) {
result[i]=String.valueOf(str.charAt(i))
}
return result
}
public static void main(String[] args) {
int[] arr1=new int[]{3,0,0,0}
int[] arr2=new int[]{2,0,0,0}
String[] str=ListArr(arr1,arr2)
for(int i=0i<str.lengthi++){
System.out.print(str[i]+",")
}
}
}
//望采纳!!!
读入键盘输入的每个字节,注意,如果不是换行字符,就累加到buf当中;
如果是换行,那就把buf当中的东西创建为String,显示出来,并复位,重新开始读键盘了。
关于从0到0,仅当你上来就敲一个回车,这时候创建一个空串而已。
挺简单的啊。。 关键在于理解heapimport java.util.Arrays
public class Du {
public static void main(String[] args) {
int[] testAry1 = {1, 3, 5, 7, 9, 11}
System.out.println("{1, 3, 5, 7, 9, 11} is " + (isHeap(testAry1)? "": "NOT ") + "heap array.")
int[] testAry2 = {1, 3, 5, 7, 13, 9, 11}
System.out.println("{1, 3, 5, 7, 13, 9, 11} is " + (isHeap(testAry2)? "":"NOT ") + "heap array.")
}
/**
* Will receive an integer heap array, method will return true or false
* depending on whether the array is believed to be a valid heap or not
*
* @param heap
*0-based integer array
* @return true if integer array is a heap, else false
*/
public static boolean isHeap(int[] heap) {
if(heap == null || heap.length == 0){
return false
}
int[] ary = new int[heap.length]
for(int i = 0i <heap.lengthi++){
ary[i] = heap[i]
}
Arrays.sort(ary)
for(int i = 0i <heap.lengthi++){
if(ary[i] != heap[i]){
return false
}
}
return true
}
}
---------------
{1, 3, 5, 7, 9, 11} is heap array
{1, 3, 5, 7, 13, 9, 11} is NOT heap array
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)