MàJ par récupération sur Clé USB et dans /mnt/hd/Chargement du pc portable
This commit is contained in:
7
G5a/Solutions/2-exoSyntaxeJava/Bonjour.java
Normal file
7
G5a/Solutions/2-exoSyntaxeJava/Bonjour.java
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
class Bonjour { // essai de hello world
|
||||
public static void main (String[] args) {
|
||||
System.out.println ("Bonjour !");
|
||||
|
||||
}
|
||||
}
|
11
G5a/Solutions/2-exoSyntaxeJava/BonjourToi1.java
Normal file
11
G5a/Solutions/2-exoSyntaxeJava/BonjourToi1.java
Normal file
@ -0,0 +1,11 @@
|
||||
import iutsud.Console;
|
||||
class BonjourToi1{ // essai d'entr<74>e-sortie caractere avec le package iutsud
|
||||
public static void main (String[] args) {
|
||||
String nom;int an;
|
||||
System.out.print ("tapez votre nom : ");
|
||||
nom=Console.readLine();
|
||||
System.out.print ("tapez votre annee de naissance : ");
|
||||
an=Console.readInt();
|
||||
System.out.println ("Bonjour "+nom+" ! Vous avez "+(2007-an)+" ans");
|
||||
}
|
||||
}
|
15
G5a/Solutions/2-exoSyntaxeJava/BonjourToi2.java
Normal file
15
G5a/Solutions/2-exoSyntaxeJava/BonjourToi2.java
Normal file
@ -0,0 +1,15 @@
|
||||
import javax.swing.JOptionPane;
|
||||
import java.util.Calendar;
|
||||
class BonjourToi2 { // essai de hello world avec une entree et une sortie Swing
|
||||
public static void main (String[] args) {
|
||||
String nom,ch;
|
||||
int an,anneeCourante;
|
||||
anneeCourante=Calendar.getInstance().get(Calendar.YEAR);
|
||||
nom=JOptionPane.showInputDialog("taper votre nom ");
|
||||
ch=JOptionPane.showInputDialog("taper votre annee de naissance (4chiffres)");
|
||||
System.out.println("nom="+nom+"; naiss="+ch+"; annee courante : "+anneeCourante);
|
||||
an=Integer.parseInt(ch);
|
||||
JOptionPane.showMessageDialog(null,"Bonjour "+nom+"! Vous avez "+(anneeCourante-an)+"ans");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
13
G5a/Solutions/2-exoSyntaxeJava/InverseArgs.java
Normal file
13
G5a/Solutions/2-exoSyntaxeJava/InverseArgs.java
Normal file
@ -0,0 +1,13 @@
|
||||
public class InverseArgs {
|
||||
public static void main (String[] args) {
|
||||
int longr;
|
||||
longr=args.length;
|
||||
if (longr==0)
|
||||
System.out.println ("il n'y a pas d'arguments !");
|
||||
else System.out.println("nb d'args :"+longr);
|
||||
for (int i =longr-1 ; i>=0; i--) {
|
||||
System.out.print(" "+args[i]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
26
G5a/Solutions/2-exoSyntaxeJava/Premier.java
Normal file
26
G5a/Solutions/2-exoSyntaxeJava/Premier.java
Normal file
@ -0,0 +1,26 @@
|
||||
import javax.swing.JOptionPane;
|
||||
class Premier { // Determine si un nb est premier ou non
|
||||
public static void main (String[] args) {
|
||||
String nb,reponse ;
|
||||
int n;
|
||||
boolean premier;
|
||||
nb=JOptionPane.showInputDialog("tapez votre nombre");
|
||||
n=Integer.parseInt(nb);
|
||||
while (n!=0) {
|
||||
premier = true;
|
||||
if (n==1) {JOptionPane.showMessageDialog(null,"1 n'est pas premier par convention ");
|
||||
premier=false;}
|
||||
for (int i=2;i<n; i++) {
|
||||
System.out.println(n+" "+i+" "+n%i);
|
||||
if (n%i==0) {
|
||||
JOptionPane.showMessageDialog(null,n+" n'est pas premier :multiple de "+ i);
|
||||
premier=false;
|
||||
break;}
|
||||
}
|
||||
if (premier)JOptionPane.showMessageDialog(null,n+" est un nb premier ");
|
||||
nb=JOptionPane.showInputDialog("tapez votre nombre");
|
||||
n=Integer.parseInt(nb);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
25
G5a/Solutions/2-exoSyntaxeJava/Puissance.java
Normal file
25
G5a/Solutions/2-exoSyntaxeJava/Puissance.java
Normal file
@ -0,0 +1,25 @@
|
||||
import iutsud.Console;
|
||||
/** calcul de x puissance y avec un algorithme basique !*/
|
||||
class Puissance{ // calcul de x puissance y avec un algorithme basique
|
||||
public static void main (String[] args) {
|
||||
int x,y,p;
|
||||
System.out.println ("Calcul de x puissance y");
|
||||
System.out.print ("tapez la valeur de x : ");
|
||||
x=Console.readInt();
|
||||
System.out.print ("tapez la valeur de y : ");
|
||||
y=Console.readInt();
|
||||
if (y==0)
|
||||
if (x==0)
|
||||
System.out.println("0 puissance 0 est indefini");
|
||||
else System.out.println(x+ " puissance 0 = 1");
|
||||
|
||||
else {
|
||||
p=1;
|
||||
for (int i=0;i<y;i++) {
|
||||
p=p*x;
|
||||
}
|
||||
System.out.println(x+ " puissance "+y +" ="+ p);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
17
G5a/Solutions/2-exoSyntaxeJava/SommeEntiers.java
Normal file
17
G5a/Solutions/2-exoSyntaxeJava/SommeEntiers.java
Normal file
@ -0,0 +1,17 @@
|
||||
public class SommeEntiers {
|
||||
public static void main (String args[]) {
|
||||
int longr=args.length;
|
||||
switch (longr){
|
||||
case 0 : System.out.println("Eh banane, t'as oublie les arguments !!!");
|
||||
break;
|
||||
case 1 : System.out.println("Quoi, seulement un arg ? "+args[0]);
|
||||
default :
|
||||
int somme=0;
|
||||
for (int i=0 ; i<args.length ; i++) {
|
||||
int j=Integer.parseInt(args[i]);
|
||||
somme+=j;
|
||||
}
|
||||
System.out.println("somme : "+somme);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user