计算机网络-子网划分【Java版】
package com ;
import java. util. Scanner ;
import java. util. regex. Matcher ;
import java. util. regex. Pattern ;
public class Main {
public static Scanner sc = new Scanner ( System . in) ;
public static String networkAddress;
public static int NUM;
public static int [ ] intNetworkAddress = new int [ 4 ] ;
public static String TYPE;
public static boolean isNet1 ( ) {
String regStr = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$" ;
return networkAddress. matches ( regStr) ;
}
public static boolean isNet2 ( ) {
if ( isNet1 ( ) ) {
Matcher matcher = Pattern . compile ( "[0-9]+" ) . matcher ( networkAddress) ;
int i = 0 ;
while ( matcher. find ( ) ) {
intNetworkAddress[ i] = Integer . parseInt ( matcher. group ( 0 ) ) ;
i++ ;
}
if ( intNetworkAddress[ 0 ] >= 0 && intNetworkAddress[ 0 ] <= 223 ) {
return true ;
}
}
return false ;
}
public static boolean isNet3 ( ) {
if ( isNet2 ( ) ) {
int xx;
int numType = intNetworkAddress[ 0 ] ;
if ( numType <= 127 ) {
TYPE = "A" ;
xx = 8 ;
} else if ( numType <= 191 ) {
TYPE = "B" ;
xx = 16 ;
} else {
TYPE = "C" ;
xx = 24 ;
}
if ( xx + NUM <= 30 ) {
return true ;
}
}
return false ;
}
public static int erJinZhiToShiJinZhi ( String str) {
StringBuffer sb = new StringBuffer ( str) . reverse ( ) ;
int sum = 0 ;
for ( int i = 0 ; i < str. length ( ) ; i++ ) {
int tmp = sb