chapter 8 done

This commit is contained in:
Rémi Heredero 2021-11-29 15:17:27 +01:00
parent e9a3803897
commit 5e523fda0b
5 changed files with 101 additions and 2 deletions

View File

@ -1,5 +1,8 @@
package C08_Structures_de_donnees.C081_Enum; package C08_Structures_de_donnees.C081_Enum;
/**
* @author Rémi Heredero
*/
enum Glace {VANILLE, CHOCOLAT, FRAISE, MANGUE}; enum Glace {VANILLE, CHOCOLAT, FRAISE, MANGUE};
// enum Cat {MINOU, CHATONS, CONNAIS_PAS_D_AUTRES, TOTO}; // enum Cat {MINOU, CHATONS, CONNAIS_PAS_D_AUTRES, TOTO};
public class App { public class App {

View File

@ -1,5 +1,8 @@
package C08_Structures_de_donnees.C082_Tableaux; package C08_Structures_de_donnees.C082_Tableaux;
/**
* @author Rémi Heredero
*/
public class Exercice1 { public class Exercice1 {
public static void main(String[] args) { public static void main(String[] args) {
@ -14,6 +17,5 @@ public class Exercice1 {
for (String string : bar) { for (String string : bar) {
System.out.println(string); System.out.println(string);
} }
} }
} }

View File

@ -1,7 +1,16 @@
package C08_Structures_de_donnees.C083_Operations_sur_tableaux; package C08_Structures_de_donnees.C083_Operations_sur_tableaux;
/**
* @author Rémi Heredero
*/
public class App { public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("Hello, World!"); int[][] foo = new int[3][3];
for (int[] is : foo) {
for (int is2 : is) {
is2 = 1;
System.out.println(is2);
}
}
} }
} }

View File

@ -0,0 +1,56 @@
package C08_Structures_de_donnees.C083_Operations_sur_tableaux;
/**
* @author Rémi Heredero
* @Klagarge
*/
public class Exercice2 {
public static void main(String[] args) {
int[] ex2_1 = {2, 5, 3, 1};
int grand = 0;
for (int i : ex2_1) {
grand = i>grand ? i:grand;
}
System.out.println("Exercice 2.1: " + grand);
String[] ex2_2 = {"hello", "je suis", "edmund"};
int e = 0;
for (String s : ex2_2) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'e') {
e++;
}
}
}
System.out.println("Exercice 2.2: " + e);
int[] v1 = {1,2,3};
int[] v2 = {4,3,2};
int [] sum = add(v1, v2);
for (int i : sum) {
System.out.println(i);
}
}
/**
* @author Rémi Heredero
* @param a tableau d'entrée a
* @param b tableau d'entrée b
* @return somme des deux tableaux d'entrée
*/
public static int[] add(int[] a, int[] b) {
if (a.length != b.length) {
return null;
}
int[] tmp = new int[a.length];
for (int i = 0; i < tmp.length; i++) {
tmp[i] = a[i] + b[i];
}
return tmp;
}
}

View File

@ -0,0 +1,29 @@
package C08_Structures_de_donnees.C083_Operations_sur_tableaux;
/**
* @author Rémi Heredero
* @Klagarge
*/
public class Exercice3 {
public static void main(String[] args) {
double[] a = {1.2, 3.2, 4.4, 5.5};
double[] b = {1.2, 2.1, 3.3, 2.5, 4.5};
int Ra = isSorted(a); // returns -1, the array is sorted
int Rb = isSorted(b); // returns 3, as 2.5 is < than 3.3
System.out.println(Ra);
System.out.println(Rb);
}
public static int isSorted(double[] a) {
for (int i = 1; i < a.length; i++) {
if (a[i] < a[i-1]) {
return i;
}
}
return -1;
}
}