從我使用java開始已經有一段時間了。我試圖將00:00:00:00:00:00格式的mac地址轉換爲0000.0000.0000格式。該程序非常基本,只是要求用戶輸入mac地址。它應該轉換它並顯示轉換後的mac地址。我認爲我很接近,但只是不知道如何獲得正確的格式。我現在得到的輸出有。在正確的位置,但我不知道如何去掉冒號。任何幫助表示讚賞。請求將mac地址格式轉換爲不同格式的幫助
import java.util.*;
public class macAdd {
public static void main(String[] args)
{
Scanner userinput = new Scanner(System.in);
String mac;
System.out.print("Copy and paste the MAC address from system : ");
mac = userinput.next();
char macDivide = '.';
String newMac = mac.replaceAll("(.{4})", "$1"+macDivide);
System.out.println("Paste the following result into the system");
System.out.println(" This is the correct mac " + newMac);
}
如果'.'位於正確的位置,並且所有內容都只是調用'newMac = newMac.replaceAll(「:」,「」);'該工作 – 3kings