package p1;
專注于為中小企業(yè)提供做網(wǎng)站、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)西安免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
import java.util.Arrays;
import java.util.LinkedList;
public class Guy
{
public static void recursionSub ( LinkedListint[] list, int count, int[] array, int ind, int start, int... indexs )
{
start++;
if (start count - 1)
{
return;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs = ind; indexs array.length; indexs++ )
{
recursionSub (list, count, array, indexs + 1, start, indexs);
if (start == count - 1)
{
int[] temp = new int[count];
for ( int i = count - 1; i = 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
list.add (temp);
}
}
}
public static void main ( String[] args )
{
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
LinkedListint[] list = new LinkedListint[] ();
recursionSub (list, 3, array, 0, -1);
for ( int[] strings : list )
{
System.out.println (Arrays.toString (strings));
}
}
}
javascript 和java都不是一個道理的,不是說轉(zhuǎn)換就可以的,為什么很多人喜歡跨語言轉(zhuǎn)換代碼,你們?yōu)槭裁床荒苓@樣問呢:如何用java來實現(xiàn)某種功能,豈不是更好?
不必轉(zhuǎn)換,我早已熟透組合排列算法:java如下
import?java.util.Arrays;
import?java.util.LinkedList;
public?class?Guy
{
public?static?void?recursionSub?(?LinkedListint[]?list,?int?count,?int[]?array,?int?ind,?int?start,?int...?indexs?)
{
start++;
if?(start??count?-?1)
{
return;
}
if?(start?==?0)
{
indexs?=?new?int[array.length];
}
for?(?indexs?=?ind;?indexs??array.length;?indexs++?)
{
recursionSub?(list,?count,?array,?indexs?+?1,?start,?indexs);
if?(start?==?count?-?1)
{
int[]?temp?=?new?int[count];
for?(?int?i?=?count?-?1;?i?=?0;?i--?)
{
temp[start?-?i]?=?array[indexs[start?-?i]];
}
list.add?(temp);
}
}
}
public?static?void?main?(?String[]?args?)
{
int[]?array?=?{?1,?2,?3,?4,?5,?6,?7,?8,?9?};
LinkedListint[]?list?=?new?LinkedListint[]?();
recursionSub?(list,?3,?array,?0,?-1);
for?(?int[]?strings?:?list?)
{
System.out.println?(Arrays.toString?(strings));
}
}
}
package p1;
import java.util.Arrays;
import java.util.LinkedList;
public class Guy
{
public static void recursionSub ( LinkedListint[] list, int count, int[] array, int ind, int start, int... indexs )
{
start++;
if (start count - 1)
{
return;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs = ind; indexs array.length; indexs++ )
{
recursionSub (list, count, array, indexs + 1, start, indexs);
if (start == count - 1)
{
int[] temp = new int[count];
for ( int i = count - 1; i = 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
list.add (temp);
}
}
}
public static void main ( String[] args )
{
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
LinkedListint[] list = new LinkedListint[] ();
recursionSub (list, 3, array, 0, -1);
for ( int[] strings : list )
{
System.out.println (Arrays.toString (strings));
}
}
}
理解他的原理就好寫了。
所有參數(shù)?排除?時間戳,按照字母順序排序,然后連接起來?和?appKey?以及?appSercet?進(jìn)行md5?運算。
排序可以使用?String?[]keys?=?map.keyset().toarray()?獲取后使用?Collections?進(jìn)行sort。
有個類似的,可以參考一下:
public?static?boolean?signVerify(String?appSecret,MapString,?String?params){
MapString,?String?map=new?HashMapString,?String();
map.put("appSecret",?appSecret);
for(String?key:params.keySet()){
if(!key.equals("sign")){
map.put(key,?params.get(key));
}
}
String?sign=sign(map);
if(sign.equals(params.get("sign"))){
return?true;
}
return?false;
}
private?static?String?toHexValue(byte[]?messageDigest)?{
if?(messageDigest?==?null)
return?"";
StringBuilder?hexValue?=?new?StringBuilder();
for?(byte?aMessageDigest?:?messageDigest)?{
int?val?=?0xFF??aMessageDigest;
if?(val??16)?{
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
return?hexValue.toString();
}
/**
?*?
?*?@param?params
?*?@return
?*/
public?static?String?sign(MapString,String?params){
ListString?keys=new?ArrayListString(params.keySet());
Collections.sort(keys);
String?string="";
for(String?s:keys){
string+=params.get(s);
}
String?sign="";
try?{
sign?=?toHexValue(encryptMD5(string.getBytes(Charset.forName("utf-8"))));
}?catch?(Exception?e)?{
e.printStackTrace();
throw?new?RuntimeException("md5?error");
}
return?sign;
}
private?static?byte[]?encryptMD5(byte[]?data)throws?Exception{
MessageDigest?md5?=?MessageDigest.getInstance("MD5");
md5.update(data);
return?md5.digest();
}
public?static?void?main(String[]?args)?{
String?appKey="key";
String?appSecret="secret";
MapString,?String?params=new?HashMapString,?String();
params.put("appKey",?appKey);
params.put("appSecret",?appSecret);
params.put("date",?new?Date().getTime()+"");
String?sign=sign(params);
params.put("sign",?sign);
System.out.println(signVerify(appSecret,?params));
}