導航:首頁 > 編程語言 > 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字元串移位相關的資料

熱點內容
核桃編程如何退錢 瀏覽:17
如何查看預約app 瀏覽:774
數控哪個編程軟體速度最快 瀏覽:135
qq表情白眼是哪個 瀏覽:965
shell循環文件名 瀏覽:602
照片3d建模源代碼 瀏覽:434
西安iPhone6升級內存 瀏覽:84
小學生的編程的課是學什麼的 瀏覽:114
就業下載什麼app 瀏覽:191
個人配置文件重定向到D盤 瀏覽:22
js屏幕寬度 瀏覽:312
sql查找某列重復資料庫 瀏覽:48
智行火車票用微信支付 瀏覽:262
網路定價過程哪些內容發生變化 瀏覽:200
dubbo服務提供者的配置文件 瀏覽:182
win8系統如何壓縮文件 瀏覽:875
網站怎麼上傳代碼 瀏覽:4
java日誌的好處 瀏覽:103
武漢奇米網路怎麼樣 瀏覽:689
筆記本如何恢復原來數據 瀏覽:76

友情鏈接