Docsity

Notes sur le thème de java , Notes de Application informatique

Toggle sidebar
bg1
Ex1
/*
Premier programme java : afficher bonjour.
*/
public class bonjour
{
public static void main(String args[])
{
System.out.println("Bonjour le monde!");
}
}
Ex2
class Compare1
{
public static void main(String args[])
{
int a = 10;
int b = 12;
System.out.println("L'entier A vaut "+a+".");
System.out.println("L'entier B vaut "+b+".");
if (a<b)
System.out.println("A est plus petit que B.");
else if (a == b)
System.out.println("A est egal à B.");
else
System.out.println("A est plus grand que B.");
}
}
Ex3
/*
Afficher bonjour en tenant compte d'un éventuel
paramètre passé sur la ligne de commande.
*/
public class bonjour2
{
public static void main(String args[])
{
if (args.length==0)
System.out.println("Bonjour le monde!");
else
System.out.println("Bonjour "+args[0]+" ! ");
}
}
Ex4
class Compare2 {
public static void main(String args[]) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
System.out.println("L'entier A vaut "+a+".");
System.out.println("L'entier B vaut "+b+".");
if (a<b)
pf2

Aperçu partiel du texte

Télécharge Notes sur le thème de java et plus Notes au format PDF de Application informatique sur Docsity uniquement!

Ex

Premier programme java : afficher bonjour. */ public class bonjour { public static void main(String args[]) { System.out.println("Bonjour le monde!"); } }

Ex

class Compare { public static void main(String args[]) { int a = 10; int b = 12; System.out.println("L'entier A vaut "+a+"."); System.out.println("L'entier B vaut "+b+"."); if (a<b) System.out.println("A est plus petit que B."); else if (a == b) System.out.println("A est egal à B."); else System.out.println("A est plus grand que B."); } }

Ex

Afficher bonjour en tenant compte d'un éventuel paramètre passé sur la ligne de commande. */ public class bonjour { public static void main(String args[]) { if (args.length==0) System.out.println("Bonjour le monde!"); else System.out.println("Bonjour "+args[0]+"! "); } }

Ex

class Compare2 { public static void main(String args[]) { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); System.out.println("L'entier A vaut "+a+"."); System.out.println("L'entier B vaut "+b+"."); if (a<b)

System.out.println("A est plus petit que B."); else if (a == b) System.out.println("A est egal à B."); else System.out.println("A est plus grand que B."); } }

Ex

public class oper {

public static void main(String args[]) { if (args.length<2) { System.out.println("Passer deux nombres en paramètre !"); System.exit(1); } else { int n0=Integer.parseInt(args[0]); int n1=Integer.parseInt(args[1]); int som=n0+n1; int diff=n0-n1; int prod=n0*n1; System.out.println("Somme : "+som); System.out.println("Différence : "+diff); System.out.println("Produit : "+prod); if (n1==0) System.out.println("Division par zéro !"); else { int quot=n0/n1; System.out.println("Quotient : "+quot); } } }

Ex

public class note {

public static void main(String args[]) { if (args.length==0) {

System.out.println("Passer une note en paramètre !"); System.exit(1); } else { int n=Integer.parseInt(args[0]); if (n>=10) System.out.println("Vous êtes reçu."); else if (n>=8) System.out.println("Vous devez passer l'oral."); else System.out.println("Vous êtes recalé."); } }