This commit is contained in:
Debucquoy Anthony 2023-03-09 07:38:52 +01:00
parent 2109fa74c0
commit d3c715a655
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
5 changed files with 92 additions and 0 deletions

BIN
q2/tp3/ExoArray.class Normal file

Binary file not shown.

77
q2/tp3/ExoArray.java Normal file
View File

@ -0,0 +1,77 @@
import java.lang.Math;
public class ExoArray {
public static void main(String[] args) {
int[] powers = new int[20], odds = new int[20], alterns = new int[20];
for (int i = 0; i < 20; i++) {
powers[i] = (int) Math.pow(2, i+1);
odds[i] = i * 2 + 1;
alterns[i] = (int)Math.pow(-1, i) * i;
}
display(powers);
System.out.println(ordered(powers));
display(odds);
System.out.println(ordered(odds));
display(alterns);
System.out.println(ordered(alterns));
System.out.printf("%d, %d, %d\n", sum(powers), sum(odds), sum(alterns));
System.out.printf("%.2f, %.2f, %.2f\n", average(powers), average(odds), average(alterns));
}
public static void display(int[] in){
String dis = "";
for(int i: in){
dis = dis + i + " ";
}
System.out.println(dis);
}
public static int sum(int[] in){
int sum = 0;
for(int i: in){
sum += i;
}
return sum;
}
public static float average(int[] in){
return sum(in)/in.length;
}
public static int[] zipSum(int[] in1, int[] in2){
if (in1.length != in2.length) // Fail Check
return null;
int[] ret = new int[in1.length];
for (int i = 0; i < in1.length; i++) {
ret[i] = in1[i] + in2[i];
}
return ret;
}
public static float[] zipAverage(int[] in1, int[] in2){
if (in1.length != in2.length) // Fail Check
return null;
float[] ret = new float[in1.length];
for (int i = 0; i < in1.length; i++) {
ret[i] = in1[i] + in2[i] / 2;
}
return ret;
}
public static boolean ordered(int[] in){
for (int i = 1; i < in.length; i++) {
if(in[i] < in[i-1])
return false;
}
return true;
}
public static int max(int[] in){
int max = 0;
for (int i : in) {
max = max < i ? i : max;
}
return max;
}
}

BIN
q2/tp3/ExoCmd.class Normal file

Binary file not shown.

15
q2/tp3/ExoCmd.java Normal file
View File

@ -0,0 +1,15 @@
public class ExoCmd {
public static void main(String[] args) {
if (args.length < 2){
System.out.println("Vous devez entrez au moins 2 arguments (entiers)!");
return;
}
int[] args_int = new int[args.length];
for (int i = 0; i < args.length; i++) {
args_int[i] = Integer.parseInt(args[i]);
}
System.out.println("Voici les nombres que vous avez entrer:");
ExoArray.display(args_int);
System.out.printf("Sum: %d; Moyenne: %.2f", ExoArray.sum(args_int), ExoArray.average(args_int));
}
}

BIN
q2/tp3/TP3.pdf Normal file

Binary file not shown.