



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Begin with langage java with th easiest way
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




// Les directives import se placent en début de fichier import java.util.Scanner; class Age { public static void main(String[] args) { // on fera mieux plus tard! final int ANNEE_COURANTE = 2016 ; System.out.println("Donnez votre age : "); Scanner input = new Scanner(System.in); int age = input.nextInt(); int annee = ANNEE_COURANTE - age; // A partir de la semaine prochaine on pourra tester // si l'utilisateur ne nous dit pas de bêtise sur son âge! System.out.println("Votre annee de naissance est : " + annee); } }
class AgeBis { // l'objet input est déclaré ici et plus dans le corps de main private static Scanner input = new Scanner(System.in);
public static void main(String[] args) { final int ANNEE_COURANTE = 2016 ; // on fera mieux plus tard! System.out.println("Donnez votre age : "); int age = input.nextInt(); int annee = ANNEE_COURANTE - age; // a partir de la semaine prochaine on pourra tester // si l'utilisateur ne nous dit pas de betise sur son age! System.out.println("Votre annee de naissance est : " + annee); } }
import java.util.Scanner; class Degre3 { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { System.out.print("Entrez le coefficient a (int): "); int a = scanner.nextInt(); System.out.print("Entrez le coefficient b (int) "); int b = scanner.nextInt(); System.out.print("Entrez le coefficient c (int) "); int c = scanner.nextInt(); } }
import java.util.Scanner; class Degre3 { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { System.out.print("Entrez le coefficient a (int): "); int a = scanner.nextInt(); System.out.print("Entrez le coefficient b (int) "); int b = scanner.nextInt(); System.out.print("Entrez le coefficient c (int) "); int c = scanner.nextInt(); System.out.print("Entrez la valeur de la variable x (double) "); double x = scanner.nextDouble(); } }
import java.util.Scanner; class Degre3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Entrez le coefficient a (int) : "); int a = scanner.nextInt(); System.out.print("Entrez le coefficient b (int) : "); int b = scanner.nextInt();
System.out.print("Entrez le coefficient c (int) : "); int c = scanner.nextInt(); System.out.print("Entrez la valeur de la variable x (double) : "); double x = scanner.nextDouble(); double xx = x * x; double aux = a + b; double valeur = aux/ 2 * x * xx + aux * aux * xx + aux +c; System.out.println("La valeur de l'expression est: " + valeur); scanner.close(); } }
import java.util.Scanner; class RosesBlanches { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); // Entrée de données System.out.print("Combien avez-vous reçu d'argent (Frs):) "); int budget = scanner.nextInt(); // Calcul du budget livres & fournitures int budgetLivres = budget * 3 / 4 ; int resteBudget = budget - budgetLivres; // Calcul du budget pour les trois autres rubriques int autre = resteBudget / 3 ; // Calcul du nombre de cafés int nbcafes = autre / 2 ; // Calcul du nombre de numéros du Flash int nbFlash = autre / 4 ; // Calcul du nombre de billets de TSOL int nbBillets = autre / 3 ; // Calcul de l'argent restant int reste = autre % 2 + autre % 4 + autre % 3 + resteBudget % 3 ; // Affichage des résultats System.out.println("Livres et Fournitures: " + budgetLivres + " Frs."); System.out.println("Vous pouvez ensuite acheter:"); System.out.println(" " + nbcafes + " cafés à Sat"); System.out.println(" " + nbFlash + " numéros du Flash"); System.out.println(" " + nbBillets + " billets de métro"); System.out.println("et il vous restera " + reste + " Frs pour les roses blan scanner.close(); } }