導航:首頁 > 編程語言 > java字元串移位

java字元串移位

發布時間:2024-07-16 13:32:40

java字元串中的空格移位

public class Test {
private static String blank = "";
private static String space = " ";
public static void main(String[] args) {
String original = " a b c";
String[] arr = original.split(space);
//出現空格的次專數屬
int num = arr.length-1;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < num; i++) {
sb.append(space);
}
sb.append(original.replaceAll(space,blank));
System.out.println(sb.toString());
}
}

㈡ java對字元串進行簡單的移位加密

import java.util.Scanner;
/**
* 移位運算
*/
public class Shift {
public static void main(String[] args) {

Scanner objScanner = new Scanner(System.in);
System.out.println("請輸入要進行移位的數:");
int pwd = objScanner.nextInt();
System.out.println("請輸入需要移的位數:");
int offset = objScanner.nextInt();
System.out.println("移位前:"+pwd);
pwd = leftEncrypt(pwd, offset);

System.out.println("移位後:"+pwd);
}

/**
* 右移位
* @param pwd 原始密碼
* @param Offset 位移量
* @return 加密後的密碼
*/
public static int rightEncrypt(int pwd, int offset ){
return pwd >> offset;
}

/**
* 左移位
* @param pwd 原始密碼
* @param Offset 位移量
* @return 加密後的密碼
*/
public static int leftEncrypt(int pwd, int offset ){
return pwd << offset;
}
}

閱讀全文

與java字元串移位相關的資料

熱點內容
bat文件怎麼寫 瀏覽:117
http網路劫持怎麼解決 瀏覽:636
jsp中變數名參數啥意思 瀏覽:471
word工具隱藏 瀏覽:94
如何把電視網路弄好 瀏覽:739
ab5文件夾 瀏覽:505
數據模擬建模叫什麼 瀏覽:513
計算機網路可擴展性 瀏覽:809
加拿大28穩定qq群 瀏覽:263
網站設計思路怎麼寫 瀏覽:74
win10磁碟自檢文件丟失 瀏覽:475
win10掃描的文件在哪裡 瀏覽:615
pdf文件公章歪了怎麼處理 瀏覽:322
java下載文件的路徑 瀏覽:551
現在有哪些熱門的軟體編程 瀏覽:453
asp什麼文件迅雷下載 瀏覽:381
巫妖王之怒升級路線 瀏覽:348
wps如何發送文件 瀏覽:359
網站怎麼加流量 瀏覽:457
聖魔之光石破解版本 瀏覽:110

友情鏈接