27 Avril
This commit is contained in:
BIN
ControleMachineJava/Exercice1/MainExo1.class
Normal file
BIN
ControleMachineJava/Exercice1/MainExo1.class
Normal file
Binary file not shown.
35
ControleMachineJava/Exercice1/MainExo1.java
Normal file
35
ControleMachineJava/Exercice1/MainExo1.java
Normal file
@@ -0,0 +1,35 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MainExo1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
for(int j=0; j<args.length; j++){
|
||||
if (args.length==0 || Integer.parseInt(args[j])<=0){
|
||||
System.out.println("Donner un entier strictement positif en argument.");
|
||||
}else{
|
||||
int x = Integer.parseInt(args[j]);
|
||||
int[] diviseur = new int[1];
|
||||
boolean estPremier = true;
|
||||
int indice=0;
|
||||
for (int i=2; i<x; i++){
|
||||
if(x % i == 0){
|
||||
estPremier = false;
|
||||
diviseur=Arrays.copyOf(diviseur,indice+1);
|
||||
diviseur[indice]=i;
|
||||
indice++;
|
||||
}
|
||||
} if (estPremier==true){
|
||||
System.out.println("L'entier "+x+" est premier.");
|
||||
}else{
|
||||
System.out.println("L'entier "+x+" n'est pas premier.");
|
||||
System.out.println("Les diviseurs de "+x+" sont 1 et lui-meme ainsi que:");
|
||||
for (int i=0; i<diviseur.length; i++) {
|
||||
System.out.println(diviseur[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user