// Exercice 2 import java.util.Scanner; class Age { public static void main(String[] args) { int actuel, naissance, age, agemin; Scanner sc = new Scanner(System.in); System.out.print("annee actuelle ? "); actuel = sc.nextInt(); System.out.print("annee de naissance ?"); naissance = sc.nextInt(); age = actuel - naissance; agemin = age - 1; System.out.print("Si votre anniversaire est deja passe, vous avez " + age); System.out.print(" ans, sinon, vous en avez " + agemin); System.out.print("."); } } // Exercice 3 import java.util.Scanner; class Lettre { public static void main(String[] args) { String charge1, charge2, etudiant; Scanner sc = new Scanner(System.in); System.out.print("Nom du 1er charge de TP ? "); charge1 = sc.next(); System.out.print("Nom du 1er charge de TP ? "); charge2 = sc.next(); System.out.print("Nom de l'etudiant ? "); etudiant = sc.next(); System.out.print("Chers " + charge1); System.out.print(" et " + charge2); System.out.println(","); System.out.println("J'adore vos TPs, ils sont tellement \"bien\" !"); System.out.print("Signé " + etudiant); System.out.print("."); } } // Exercice 4 class ExprArith { public static void main(String[] args) { System.out.println("4 / 3 = " + 4/3); System.out.println("4 / 3.0 = " + 4/3.0); System.out.println("4 - 3 * 5 = " + (4 - 3 * 5)); System.out.println("4 - (3 * 5) = " + (4 - (3 * 5))); System.out.println("(4 - 3) * 5 = " + ((4 - 3) * 5)); System.out.println("117 % 7 = " + 117 % 7); System.out.println("0.3 - 0.2 = " + (0.3 - 0.2)); System.out.println("0.2 - 0.1 = " + (0.2 - 0.1)); System.out.println("1.3 / 0 = " + 1.3 / 0); System.out.println("2 / 0 = " + 2 / 0); System.out.println("( - 1.3) / 0 = " + ( - 1.3) / 0); System.out.println("0 / 1.3 = " + 0 / 1.3); System.out.println("0 / 0 = " + 0 / 0); } } // Exercice 5 import java.util.Scanner; public class Moyenne { public static void main(String[] args) { double somme, moyenne; somme = (double) 0.0 ; Scanner sc = new Scanner(System.in); System.out.println("Entrez les notes en appuyant sur enter entre chacunes"); somme = sc.nextDouble(); somme += sc.nextDouble(); somme += sc.nextDouble(); somme += sc.nextDouble(); System.out.println("Somme : " + somme); moyenne = somme / 4; System.out.println("Moyenne : " + moyenne); } } // Exercice 6 import java.util.Scanner; public class Cercle { public static void main(String[] args) { double rayon, perimetre, surface; Scanner sc = new Scanner(System.in); System.out.println("Rayon ? "); rayon = sc.nextDouble(); perimetre = (double) (2 * Math.PI * rayon); surface = (double) (Math.PI * rayon * rayon); System.out.println("Perimetre : " + perimetre); System.out.println("Surface : " + surface); } } // Exercice 7 import java.util.Scanner; class Temperature { public static void main(String[] args) { double celsius, fahrenheit ; Scanner sc = new Scanner(System.in); System.out.println("Temperature en Celsius ? "); celsius = sc.nextDouble(); fahrenheit = 9 * celsius / 5 + 32; System.out.println("Temperature en Fahrenheit : " + fahrenheit ); } } // Exercice 8 import java.util.Scanner; class Carat { public static void main(String[] args) { double all, met, purete ; Scanner sc = new Scanner(System.in); System.out.print("Masse de l'alliage ? "); all = sc.nextDouble(); System.out.print("Masse de métal précieux ? "); met = sc.nextDouble(); purete = (met * 24) / all; System.out.print("Purete de l'alliage (en carats) : " + purete); } } //Exercice 9 import java.util.Scanner; class Euclide { public static void main(String[] args) { int a, b, q, r; Scanner sc = new Scanner(System.in); System.out.print("Premier entier ? "); a = sc.nextInt(); System.out.print("Deuxieme entier ? "); b = sc.nextInt(); q = a / b ; r = a % b ; System.out.print(+a); System.out.print(" = " +b); System.out.print(" * " +q); System.out.print(" + " +r); } } // Exercice 10 import java.util.Scanner; class Seconde { public static void main(String[] args) { int init, min_temp, heure, minute, seconde; Scanner sc = new Scanner(System.in); System.out.print("Combien de secondes ? "); init = sc.nextInt(); seconde = init % 60; min_temp = (init - seconde) / 60; heure = min_temp / 60; minute = init % 60; System.out.print(+ min_temp); System.out.print(" secondes valent " + heure); System.out.print(" heures, " + minute); System.out.print(" minutes et " + seconde); System.out.print("secondes"); } } // Exercice 11 class Transtypage { public static void main(String[] args) { System.out.println("7.2 / 4 = " + 7.2 / 4 ); System.out.println("7 / 4.5 = " + 7 / 4.5 ); System.out.println("7.2 / 4.5 = " + 7.2 / 4.5 ); System.out.println("7 / 4 = " + 7 / 4 ); System.out.println("(int) (7.2 / 4) = " + ((int) (7.2 / 4)) ); System.out.println("(double) (7 / 4) = " + ((double) (7 / 4)) ); System.out.println("(int) 7.2 / 4 = " + ((int) 7.2 / 4) ); System.out.println("(int) 7.2 / 4.1 = " + ((int) 7.2 / 4.1) ); System.out.println("(double) 7 / 4 = " + ((double) 7 / 4) ); } } // Exercice 12 import java.util.Scanner; class Aleatoire { public static void main(String[] args) { double aleaf; int taille, n1, n2, aleai; Scanner sc = new Scanner(System.in); System.out.print("Premier nombre de l'intervalle "); n1 = sc.nextInt(); System.out.print("Deuxième nombre de l'intervalle "); n2 = sc.nextInt(); taille = n2 - n1 +1; aleaf = taille * Math.random(); aleai = (int) aleaf + n1; System.out.print(aleai); } } // Exercice 13 import java.util.Scanner; class Moyenne2 { public static void main(String[] args) { double somme, moyenne; int precision, precision2; somme = (double) 0.0 ; Scanner sc = new Scanner(System.in); System.out.println("Entrez les notes en appuyant sur enter entre chacunes"); somme = sc.nextDouble(); somme += sc.nextDouble(); somme += sc.nextDouble(); somme += sc.nextDouble(); System.out.print("Quelle précision ?"); precision = sc.nextInt(); precision2 = (int) java.lang.Math.pow(10,precision); somme = (double) ( (int) (somme * precision2) ) / precision2; System.out.println("Somme : " + somme); moyenne = somme / 4; moyenne = (double) ( (int) (moyenne * precision2) ) / precision2; System.out.println("Moyenne : " + moyenne); } } class Cercle2 { public static void main(String[] args) { double rayon, perimetre, surface; int precision, precision2; Scanner sc = new Scanner(System.in); System.out.print("Rayon ? "); rayon = sc.nextDouble(); System.out.print("Quelle précision ?"); precision = sc.nextInt(); precision2 = (int) java.lang.Math.pow(10,precision); perimetre = (double) (2 * Math.PI * rayon); perimetre = (double) ( (int) (perimetre * precision2) ) / precision2; surface = (double) (Math.PI * rayon * rayon); surface = (double) ( (int) (surface * precision2) ) / precision2; System.out.println("Perimetre : " + perimetre); System.out.println("Surface : " + surface); } } class Temperature2 { public static void main(String[] args) { double celsius, fahrenheit ; int precision, precision2; Scanner sc = new Scanner(System.in); System.out.print("Temperature en Celsius ? "); celsius = sc.nextDouble(); System.out.print("Quelle précision ?"); precision = sc.nextInt(); precision2 = (int) java.lang.Math.pow(10,precision); fahrenheit = 9 * celsius / 5 + 32; fahrenheit = (double) ( (int) (fahrenheit * precision2) ) / precision2; System.out.println("Temperature en Fahrenheit : " + fahrenheit ); } } class Carat2 { public static void main(String[] args) { double all, met, purete ; int precision, precision2; Scanner sc = new Scanner(System.in); System.out.print("Masse de l'alliage ? "); all = sc.nextDouble(); System.out.print("Masse de métal précieux ? "); met = sc.nextDouble(); System.out.print("Quelle précision ?"); precision = sc.nextInt(); precision2 = (int) java.lang.Math.pow(10,precision); purete = (met * 24) / all; purete = (double) ( (int) (purete * precision2) ) / precision2; System.out.print("Purete de l'alliage (en carats) : " + purete); } } // Exercice 14 class Bool { public static void main(String[] args) { System.out.println("10 > 5 = " + (10 > 5)); System.out.println("10 == 5 = " + (10 == 5)); System.out.println("5 == 5 = " + (5 == 5)); System.out.println("5 == 11 - 6 = " + (5 == 11 - 6)); System.out.println("false || (5 != 4) = " + (false || (5 != 4))); System.out.println("false && (5 != 4) = " + (false && (5 != 4))); System.out.println("!(30 % 3 == 0) = " + (!(30 % 3 == 0))); System.out.println("0.3 - 0.2 == 0.2 - 0.1 = " + (0.3 - 0.2 == 0.2 - 0.1)); } } // Exercice 15 import java.util.Scanner; class TestExpression { public static void main(String[] args) { int n1, n2, n3; Scanner sc = new Scanner(System.in); System.out.print("Premier nombre ? "); n1 = sc.nextInt(); System.out.print("Deuxieme nombre ? "); n2 = sc.nextInt(); System.out.print("Troisieme nombre ? "); n3 = sc.nextInt(); System.out.print ((n1 < n2)&&(n2 < n3)); } } // Exercice 16 import java.util.Scanner; public class TestAnnee { public static void main(String[] args) { int a; Scanner sc = new Scanner(System.in); System.out.print("Quelle annee ? "); a = sc.nextInt(); System.out.print ((a % 4 ==0) && (!(a % 100 == 0) || (a % 400 == 0))); } }