Article temporaire
Partiel d'Info
Exo 1
class remplissage
{
public static void main (String[] args)
{
int t1[], t2[], t3[], i;
t1=new int [200];
t2=new int [200];
t3=new int [200];
//Remplisage des tableau
for (i=0; i<200; i++)
{
t1=-25 + Math.round((float)(Math.random() * 50));
t2=-25 + Math.round((float)(Math.random() * 50));
t3=-25 + Math.round((float)(Math.random() * 50));
System.out.println(i+"|"+t1); //Affichage du tableau1
}
}
}
Exercice 2
class exercice2
{
public static void main (String[] args)
{
int t1[], t2[], t3[], taille=5, i;
t1=new int [taille];
t2=new int [taille];
t3=new int [taille];
t1[0]=1;
t1[1]=2;
t1[2]=3;
t1[3]=4;
t1[4]=5;
t2[0]=1;
t2[1]=2;
t2[2]=3;
t2[3]=4;
t2[4]=5;
addition(t1, t2, t3, taille);
System.out.println("Résultat du tableau 3 \n");
for (i=0; i<taille; i++)
{
System.out.println(t1 + "+" + t2 + "=" + t3);
}
}
static void addition(int t1[], int t2[], int t3[], int taille)
{
int i;
for (i=0; i<taille; i++)
{
t3=t1+t2;
}
}
}
Exercice 3
class exercice3
{
public static void main (String[] args)
{
int t1[], t2[], t3[], taille=200, i;
t1=new int [taille];
t2=new int [taille];
t3=new int [taille];
//Remplisage des tableau
for (i=0; i<taille; i++)
{
t1=-25 + Math.round((float)(Math.random() * 50));
t2=-25 + Math.round((float)(Math.random() * 50));
}
addition(t1, t2, t3, taille);
System.out.println("Résultat du tableau 3 \n");
for (i=0; i<taille; i++)
{
System.out.println(t1 + "+" + t2 + "=" + t3);
}
}
static void addition(int t1[], int t2[], int t3[], int taille)
{
int i;
for (i=0; i<taille; i++)
{
t3=t1+t2;
}
}
}
Exercice 4
class exercice4
{
public static void main (String[] args)
{
int t1[], t2[], taille1=4, taille2=2, schtroumpf;
t1=new int [taille1];
t2=new int [taille2];
t1[0]=4;
t1[1]=8;
t1[2]=7;
t1[3]=12;
t2[0]=3;
t2[1]=6;
schtroumpf= fct_schtroumpf(t1, t2, taille1, taille2);
System.out.println("Le nombre schtroumpf est : " + schtroumpf);
}
static int fct_schtroumpf(int t1[], int t2[], int taille1, int taille2)
{
int i, j, schtroumpf=0;
for (i=0; i<taille1; i++)
{
for (j=0; j<taille2; j++)
{
schtroumpf=schtroumpf+(t1*t2[j]);
}
}
return schtroumpf;
}
}
Exercice 5
class exercice5
{
public static void main (String[] args)
{
int t1[], t2[], taille1=4, taille2=2, i, schtroumpf;
t1=new int [taille1];
t2=new int [taille2];
//remplisage du tableau 1
for (i=0; i<taille1; i++)
{
t1=Math.round((float)(Math.random() * 50));
}
//remplisage du tableau 2
for (i=0; i<taille2; i++)
{
t2=Math.round((float)(Math.random() * 50));
}
schtroumpf= fct_schtroumpf(t1, t2, taille1, taille2);
System.out.println("Le nombre schtroumpf est : " + schtroumpf);
}
static int fct_schtroumpf(int t1[], int t2[], int taille1, int taille2)
{
int i, j, schtroumpf=0;
for (i=0; i<taille1; i++)
{
for (j=0; j<taille2; j++)
{
schtroumpf=schtroumpf+(t1*t2[j]);
}
}
return schtroumpf;
}
}
Exercice 6
class exercice6
{
public static void main (String[] args)
{
int t1[], taille=10;
t1=new int [taille];
//remplisage du tableau
t1[0]=-1;
t1[1]=-5;
t1[2]=10;
t1[3]=-8;
t1[4]=88;
t1[5]=-55;
t1[6]=4;
t1[7]=-1;
t1[8]=1;
t1[9]=-1;
somme(t1, taille);
}
static void somme(int t1[], int taille)
{
int i, positif=0, negatif=0;
for (i=0; i<taille; i++)
{
if (t1>=0)
{
positif=positif+t1;
}
else
{
negatif=negatif+t1;
}
}
System.out.println("La somme des valeurs positive est : " + positif + "\n");
System.out.println("La somme des valeurs négative est : " + negatif + "\n");
}
}
Exercice 7
class exercice7
{
public static void main (String[] args)
{
int t1[], taille=50, i;
t1=new int [taille];
//remplisage du tableau
for (i=0; i<taille; i++)
{
t1=-25 + Math.round((float)(Math.random() * 50));
}
somme(t1, taille);
}
static void somme(int t1[], int taille)
{
int i, positif=0, negatif=0;
for (i=0; i<taille; i++)
{
if (t1>=0)
{
positif=positif+t1;
}
else
{
negatif=negatif+t1;
}
}
System.out.println("La somme des valeurs positive est : " + positif + "\n");
System.out.println("La somme des valeurs négative est : " + negatif + "\n");
}
}