Merci d'avoir répondu :D
Voici le programme :
import java.util.Scanner;
public class ip {
public static void main(String[] args){
char carac = ' ';
char choix = ' ';
do {
System.out.println("Entrez une adresse ip !");
Scanner sc = new Scanner(System.in);
String ip = sc.nextLine();
if(!ip.matches("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"))
System.err.println("Votre addresse ip est incorrecte");
else {
String str[]=ip.split("\\.");
int categorie = Integer.parseInt(str[0]);
int H1 = Integer.parseInt(str[1]);
int H2 = Integer.parseInt(str[2]);
int H3 = Integer.parseInt(str[3]);
char classe = ' ';
if(categorie < 127 && categorie > 0) {
System.out.println("Votre addresse ip est de Catégorie A");
classe = 'A';
}
else if(categorie < 192 && categorie > 127) {
System.out.println("Votre addresse ip est de Catégorie B");
classe = 'B';
}
else if(categorie < 223 && categorie > 192) {
System.out.println("Votre addresse ip est de Catégorie C");
classe = 'C';
}
sc = new Scanner(System.in);
System.out.println("En combien de sous-réseaux voulez-vous le décomposer ? !");
int sr = sc.nextInt();
int bit=0;
int tableau[] = {1,2,4,8,16,32,64,128,256,512};
for(int i=0; i < 9; i++) {
if(sr == tableau[i] && sr == Math.pow(2,i)) bit = i;
else if (sr < tableau[i+1] && sr > tableau[i-1]) bit = i;
}
System.out.println("Le nombre de bit est "+bit);
if(classe == 'A') {
System.out.println("Address du réseau est :"+categorie+".0.0.0");
if(bit < 8) {
String h1 = "00000000" ;
String h2 = "00000000";
String h3 = "00000000";
String nb[] = new String[h1.length()];
nb[0]=h1.substring(0,bit);
nb[1]=h1.substring(bit,h1.length());
long binaire[]= new long[(long) Math.pow(2, nb[0].length())];
long chaines[]= new long[(long) Math.pow(2, binaire.length)];
long machine[]= new long[(long) Math.pow(2, nb[1].length())];
long chainem[]= new long[(long) Math.pow(2, machine.length)];
String zero ="0";
for(int i=0; i < binaire.length; i++){
do{
String chaine =Integer.toBinaryString(i);
String chaine2 = zero.concat(chaine);
chaines[i]=Integer.parseInt(chaine2);
}while(chaines[i] != binaire.length);
String chain1 = Long.toString(chaines[i]);
String result = chain1.concat(nb[1]);
int decimal = Integer.parseInt(result,2);
String résultat = nb[1].replaceAll("0","1");
String resultt = chain1.concat(résultat);
int decima = Integer.parseInt(resultt,2);
System.out.println("Address broadcast du sous réseau :"+i+" est :"+categorie+"."+decimal+".0.0");
System.out.println("Le sous réseau "+i+" accepte des address entre :"+categorie+"."+decimal+".0.1 a "+categorie+"."+decima+".255.254" );
System.out.println("Address broadcast du sous réseau :"+i+" est :"+categorie+"."+decima+".255.255");
}
}
System.out.println("Address broadcast est :"+categorie+".255.255.255");
}
}
System.out.println("Voulez-vous recommencer ? O/N");
sc = new Scanner(System.in);
carac= sc.next().charAt(0);
}while(carac == 'O');
}
}
Il faut faire partie de la solution et non du problème ;-)