Skip to content
Snippets Groups Projects
Commit 7a360487 authored by jonas.stirnema's avatar jonas.stirnema
Browse files

Add the first exercices

parents
No related branches found
No related tags found
No related merge requests found
File added
import java.io.Reader;
import java.util.Scanner;
public class Lecture {
public static int askInt() {
Scanner rd = new Scanner(System.in);
int num = 0;
boolean run = true;
while (run) {
System.out.print("Entrez une valeur entière :");
try {
num = rd.nextInt();
run = false;
} catch (Exception e) {
System.out.println("Valeur erronée");
rd.next();
}
}
// rd.close();
return num;
}
public static int askIntRec() {
Scanner sc = new Scanner(System.in);
int num = 0;
System.out.print("Entrez une valeur entière :");
try {
num = sc.nextInt();
sc.close();
} catch (Exception e) {
System.out.println("Valeur erronée");
sc.next();
num = askIntRec();
}
return num;
}
public static void main(String[] args) {
System.out.println("Le méthode a retourné " + askInt());
System.out.println("Le méthode a retourné " + askIntRec());
}
}
\ No newline at end of file
File added
import java.lang.Math;
import java.io.Reader;
import java.util.Scanner;
import javax.lang.model.util.ElementScanner14;
public class Serie1 {
public static void whileTests(int i) {
do {
System.out.println(i++);
} while (i < 5);
}
static void g(int n, float x) {
System.out.println(x);
}
static void printTriangle(int n) {
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
static void printSapin(int h) {
for (int i = 1; i < h + 1; i++) {
for (int j = 0; j < h - i; j++) {
System.out.print(" ");
}
for (int x = 0; x < i * 2 - 1; x++) {
System.out.print("*");
}
System.out.println();
}
}
static double GetPi(int n) {
double sum = 0.0;
for (int i = 1; i < n; i++) {
sum += 1.0 / (i * i * i * i);
}
return Math.pow(sum * 90.0, 1.0 / 4.0);
}
public static void Serpent() {
Scanner rd = new Scanner(System.in);
String head = "(^^)";
boolean run = true;
int size = 0;
while (run) {
System.out.println("*".repeat(size) + head);
switch (rd.next()) {
case "+":
size++;
System.out.println("DEBUG");
break;
case "-":
if (size > 0) {
size--;
} else {
run = false;
}
break;
}
}
rd.close();
}
public static void main(String[] args) {
// whileTests(0);
// g(10, 10);
// printTriangle(4);
// printSapin(4);
// System.out.println((GetPi(100)));
Serpent();
}
}
\ No newline at end of file
public class Vecteur {
public static double[] Add(double[] a, double[] b) {
if (a.length != b.length)
return new double[0];
double[] out = new double[a.length];
for (int i = 0; i < a.length; i++) {
out[i] = a[i] + b[i];
}
return out;
}
public static double[] mul(double[] a, double b) {
for (int i = 0; i < a.length; i++) {
a[i] = a[i] * b;
}
return a;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment