This commit is contained in:
2023-04-27 11:27:11 +02:00
parent bfcbd64735
commit 93c00d1ed0
24 changed files with 483 additions and 0 deletions

Binary file not shown.

View 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]);
}
}
}
}
}
}

View File

@@ -0,0 +1,13 @@
import java.awt.*;
import javax.swing.*;
import java.lang.*;
public class Entiexte {
private String entier;
public Entiexte(String nombre) {
this.entier=nombre;
}
public Entiexte(int x) {
this.entier=x;
}

Binary file not shown.

View File

@@ -0,0 +1,52 @@
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class MainExo3 {
public static ObjetAleatoire genererOA(){
ObjetAleatoire p;
Random r = new Random();
if((r.nextInt()%2)==0){
p = new Piece();
}else{
p = new PiecePipee();
} return p;
}
public static void main(String[] args) {
ObjetAleatoire o;
int f;
int nbrf=0;
int nbrp=0;
int truquer=0;
o=genererOA();
o.lancer();
f=o.lire();
if(f==1||f==-1){
System.out.println("Vous avez fait face.");
}else{
System.out.println("Vous avez fait pile.");
} for(int j=0; j<10 ;j++){
nbrf=0;
nbrp=0;
for(int i=0;i<100;i++){
o.lancer();
f=o.lire();
if(f==1||f==-1){
nbrf++;
}else{
nbrp++;
}
} if (nbrp<=nbrf){
truquer++;
}else{
truquer--;
}
} if (truquer>=-7){
System.out.println("Piece non truquer");
}else{
System.out.println("Piece truquer");
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,4 @@
public interface ObjetAleatoire{
void lancer();
int lire();
}

Binary file not shown.

View File

@@ -0,0 +1,21 @@
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Piece implements ObjetAleatoire {
private int faceVisible; // 0 = pile; 1 = face.
public Piece(){
this.faceVisible=faceVisible;
}
public void lancer(){
Random r = new Random();
this.faceVisible=(r.nextInt()%2);
}
public int lire(){
return faceVisible;
}
}

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class PiecePipee implements ObjetAleatoire {
private int faceVisible; // 0 = pile; 1 = face.
public PiecePipee(){
this.faceVisible=faceVisible;
}
public void lancer(){
Random r = new Random();
if(r.nextInt()%10<7&&r.nextInt()%10>-7){
this.faceVisible=0;
}else{
this.faceVisible=1;
}
}
public int lire(){
return faceVisible;
}
}

Binary file not shown.