Java
Java
Java
int a;
String r;
String s;
clavier.nextLine();
System.out.println("tu as "+a);
System.out.println("ton nom"+r);
System.out.println("ton prenom"+s);
}
Affiche
donner ton nbre
5
donner ton texte
yass
donner ton 2eme texte
mecher
tu as 5
ton nomyass
ton prenommecher
Boucle for
int age;
do {
System.out.println("donner ton age");
age=clavier.nextInt();
} while (age<0);
System.out.println("tu es grand");
}
Boucle while
int i=100;
while (i<=45); {
System.out.println("donner ton age");
// Jeux
nbr_pc = (int)((Math.random()*999)+1);
do {
System.out.print("donner le nbr :");
nbr_user=clavier.nextInt();
if(nbr_pc == nbr_user) {
System.out.println("c bien");
}
else if (nbr_pc < nbr_user) {
System.out.println("tu es loin");
}
else {
System.out.println("tu es prés");
}
tab2[i] = tab1[i];
** 55
66
77
88
0
0
if(tab1.length != tab2.length) {
System.out.println("c est differents");
}else {
int i=0;
while(i< tab1.length && tab1[i]== tab2[i]) {
++i;
}
if (i>= tab1.length) {
System.out.println("sont egaux");
}
else {
System.out.println("sont differs");
}
}
int b = methode(5);
System.out.println(b+2);
}
static int methode (int nbre) {
return nbre*2;
}
*** 12
// methode
ditesbonjour();
ditesbonjour();
ditesbonjour();
}
System.out.println(methode2());
}
*** wawawaw
//factoriel
System.out.println(factoriel(4));
}
static int factoriel(int nb) {
if(nb<0) {
System.out.println("tu as entrer un nbre negatif");
return -1;
}else {
int result = 1;
for(int i =1;i<=nb;i++) {
result = result*i;
}
return result;
}
*** 24
System.out.println(factoriel(4));
}
static int factoriel (int nb) {
if (nb==0 || nb==1 ) {
return nb = 1;
}else {
return nb*(factoriel(nb-1));
}
**24
// Random jeux
import java.util.Random;
System.out.println("hummmm...");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(success) {
System.out.println("yes");
}else {
System.out.println("no");
}
}
}
*** do you love me
hummmm... **(il reste 5 seconde puis continue)
yes
// jeux
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
for(int i=0;i<NUMBER_OF_QUESTIONS;i++) {
do{
Random random = new Random();
index = random.nextInt(tab.length);
} while(tabdynamique.contains(index));
tabdynamique.add(index);
answer = clavier.nextLine();
if(capital.equalsIgnoreCase(answer)) {
System.out.println("true");
score++;
}else {
System.out.printf("false, il faut repondre %s\n",
capital);
}
}
System.out.printf("le score est %d/%d", score,NUMBER_OF_QUESTIONS);
clavier.close();
}