Tableau java
Fermé
-=(L)=-
Messages postés
184
Date d'inscription
jeudi 8 février 2007
Statut
Membre
Dernière intervention
13 mars 2007
-
28 févr. 2007 à 12:59
foudinfo - 27 févr. 2010 à 17:37
foudinfo - 27 févr. 2010 à 17:37
A voir également:
- Tableau java
- Tableau croisé dynamique - Guide
- Jeux java itel ✓ - Forum Jeux vidéo
- Java runtime - Télécharger - Langages
- Tableau ascii - Guide
- Java apk - Télécharger - Langages
8 réponses
Hello,
J'ai regarder ton code et première remarque que j'aurais à te faire, serait de créer une class Ballon
public class Ballon() {
private String identificateur; // identifier un ballon
private int taille; // taille du ballon
// constructeur
public Ballon(String identificateur, int taille) {
this.identificateur=identificateur ;
this.taille=taille ;
}
//il faudra créer les getter/setter.
}
et ensuite dans la class essai du construit un tableau de ballon :
Ballon TableauBallon[][] = new Ballon[10][2]
méthode détruire :
private static void detruire_element_instance() {
System.out.println("Quel ballon souhaitez-vous supprimer ?");
System.out.println("ligne du ballon : ");
int i = Integer.parseInt(Keyboard.readString());
System.out.println("colone du ballon :");
int j = Integer.parseInt(Keyboard.readString());
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
System.out.println("Le ballon a ete supprime");
}
}
méthode afficher :
private static void afficher_instance() {
for (int x = 0 ; x < tableau.length ; x++ ){
for (int y = 0 ; y < tableau[0].length ; y++ )
System.out.println(TableauBallon[x][y]);
}
méthode créer un ballon :
private static void creer_instance() {
System.out.println("Tapez les donnees du ballon :");
System.out.println("ligne du ballon : ");
int i = Integer.parseInt(Keyboard.readString());
System.out.println("colone du ballon :");
int j = Integer.parseInt(Keyboard.readString());
System.out.println("identificateur du ballon :");
String id = Keyboard.readString();
System.out.println("taille du ballon :");
int dim = Integer.parseInt(Keyboard.readString());
// il faut encore tester que le ballon ne soit pas créer endehors du tableau.
TableauBallon[i][j] = new Ballon(id, dim) ;
}
J'ai regarder ton code et première remarque que j'aurais à te faire, serait de créer une class Ballon
public class Ballon() {
private String identificateur; // identifier un ballon
private int taille; // taille du ballon
// constructeur
public Ballon(String identificateur, int taille) {
this.identificateur=identificateur ;
this.taille=taille ;
}
//il faudra créer les getter/setter.
}
et ensuite dans la class essai du construit un tableau de ballon :
Ballon TableauBallon[][] = new Ballon[10][2]
méthode détruire :
private static void detruire_element_instance() {
System.out.println("Quel ballon souhaitez-vous supprimer ?");
System.out.println("ligne du ballon : ");
int i = Integer.parseInt(Keyboard.readString());
System.out.println("colone du ballon :");
int j = Integer.parseInt(Keyboard.readString());
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
System.out.println("Le ballon a ete supprime");
}
}
méthode afficher :
private static void afficher_instance() {
for (int x = 0 ; x < tableau.length ; x++ ){
for (int y = 0 ; y < tableau[0].length ; y++ )
System.out.println(TableauBallon[x][y]);
}
méthode créer un ballon :
private static void creer_instance() {
System.out.println("Tapez les donnees du ballon :");
System.out.println("ligne du ballon : ");
int i = Integer.parseInt(Keyboard.readString());
System.out.println("colone du ballon :");
int j = Integer.parseInt(Keyboard.readString());
System.out.println("identificateur du ballon :");
String id = Keyboard.readString();
System.out.println("taille du ballon :");
int dim = Integer.parseInt(Keyboard.readString());
// il faut encore tester que le ballon ne soit pas créer endehors du tableau.
TableauBallon[i][j] = new Ballon(id, dim) ;
}
-=(L)=-
Messages postés
184
Date d'inscription
jeudi 8 février 2007
Statut
Membre
Dernière intervention
13 mars 2007
11
28 févr. 2007 à 14:16
28 févr. 2007 à 14:16
Je comprend pas avec quel ligne de code tu supprime un élément de mon tableau
Oups, g oublié :
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
TableauBallon[i][j] = null ;
System.out.println("Le ballon a ete supprime");
}
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
TableauBallon[i][j] = null ;
System.out.println("Le ballon a ete supprime");
}
Bonjour
Je cherche cmt je peux afficher les éléments de mon tableau. Est ce que il y a personne qui connait le faire ?
voila le code de création de mon tableau :
---------------------------------------------------------------
public static void main (String args [])
{int tab[];
tab = new int[4];
tab[0]=5;
tab[1]=3;
tab[2]=7;
tab[3]=tab[1]+ tab[2];
}
------------------------------------------------------------------
Merci en avance!!!
Je cherche cmt je peux afficher les éléments de mon tableau. Est ce que il y a personne qui connait le faire ?
voila le code de création de mon tableau :
---------------------------------------------------------------
public static void main (String args [])
{int tab[];
tab = new int[4];
tab[0]=5;
tab[1]=3;
tab[2]=7;
tab[3]=tab[1]+ tab[2];
}
------------------------------------------------------------------
Merci en avance!!!
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
version 03/2010 du tableau de ballon
source 1
public class Ballon {
// init des attributs
private String identificateur; // identifier un ballon
private int taille; // taille du ballon
// constructeur methode
//constructeur methode sans parametres
public Ballon() {
}
//constructeur surxhage avec parametres
public Ballon(String identificateur, int taille) {
this.identificateur=identificateur ;
this.taille=taille ;
}
public String getIdentificateur() {
return this.identificateur;
}
public void setIdentificateur(String identificateur) {
this.identificateur = identificateur;
}
public int getTaille() {
return this.taille;
}
public void setTaille(int taille) {
this.taille = taille;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof Ballon))
return false;
Ballon castOther = (Ballon) other;
return (this.getIdentificateur() == castOther.getIdentificateur())
&& (this.getTaille() == castOther.getTaille());
}
}
///////////////////////////////////////////////////////
source 2
import java.util.Scanner;
public class ballonEssai {
static Ballon TableauBallon[][] = new Ballon[40][40];
private static void detruire_element_instance() {
Scanner sc = new Scanner(System.in);
System.out.println("Quel ballon souhaitez-vous supprimer ?");
System.out.println("ligne du ballon : ");
String str4 = sc.nextLine();
System.out.println("Vous avez saisi : " + str4);
int i = Integer.parseInt(str4);
System.out.println("colone du ballon :");
String str5 = sc.nextLine();
System.out.println("Vous avez saisi : " + str5);
int j = Integer.parseInt(str5);
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
TableauBallon[i][j] = null ;
System.out.println("Le ballon a ete supprime");
}
}
private static void afficher_instance() {
for (int x = 0 ; x < TableauBallon.length ; x++ ){
for (int y = 0 ; y < TableauBallon[0].length ; y++ )
{ try
{if (!(TableauBallon[x][y].getIdentificateur()== null)|
!(TableauBallon[x][y].getTaille()== 0))
System.out.println("ballon x>"+x+"ballon y>"+y
+"<id>"+ TableauBallon[x][y].getIdentificateur()
+"<dim>"+ TableauBallon[x][y].getTaille());
}
catch (Exception e) {
System.out.println("ballon x>"+x+"ballon y>"+y+"*****aucun ballon à afficher ");}
}
}
}
//////////////////////////////////////////////////////////
private static void creer_instance() {
System.out.println("Tapez les donnees du ballon :");
System.out.println("ligne du ballon : ");
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
System.out.println("Vous avez saisi : " + str1);
int i = Integer.parseInt(str1);
System.out.println("colone du ballon :");
String str2 = sc.nextLine();
System.out.println("Vous avez saisi : " + str2);
int j = Integer.parseInt(str2);
System.out.println("identificateur du ballon :");
String id = sc.nextLine();
System.out.println("Vous avez saisi : " + id);
System.out.println("taille du ballon :");
String str3 = sc.nextLine();
System.out.println("Vous avez saisi : " + str3);
int dim = Integer.parseInt(str3);
// il faut encore tester que le ballon ne soit pas créer endehors du tableau.
System.out.println("i>"+i+"<j>"+j+"<id>"+id+"<dim>"+dim);
TableauBallon[i][j] = new Ballon(id, dim) ;
}
public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int s = 1;
while ( s!=0){
System.out.println("+++++++++++++(MENU)+++++++++++++");
System.out.println("1) Créer un ballon");
System.out.println("2) Détruire un ballon");
System.out.println("3) Afficher la liste des ballons");
System.out.println("0) Quitter");
System.out.println("++++++++++++++++++++++++++++++++");
System.out.println("");
System.out.println("(Veuillez faire votre choix)");
String str1 = sc.nextLine();
System.out.println("Vous avez saisi : " + str1);
s= Integer.parseInt(str1);
switch (s) {
case 1 :
creer_instance();
break;
case 2 :
detruire_element_instance();
break;
case 3 :
afficher_instance();
break;
case 0 :
System.out.println("Au revoir !");
System.exit(0);
break;
}
}
}
}
source 1
public class Ballon {
// init des attributs
private String identificateur; // identifier un ballon
private int taille; // taille du ballon
// constructeur methode
//constructeur methode sans parametres
public Ballon() {
}
//constructeur surxhage avec parametres
public Ballon(String identificateur, int taille) {
this.identificateur=identificateur ;
this.taille=taille ;
}
public String getIdentificateur() {
return this.identificateur;
}
public void setIdentificateur(String identificateur) {
this.identificateur = identificateur;
}
public int getTaille() {
return this.taille;
}
public void setTaille(int taille) {
this.taille = taille;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof Ballon))
return false;
Ballon castOther = (Ballon) other;
return (this.getIdentificateur() == castOther.getIdentificateur())
&& (this.getTaille() == castOther.getTaille());
}
}
///////////////////////////////////////////////////////
source 2
import java.util.Scanner;
public class ballonEssai {
static Ballon TableauBallon[][] = new Ballon[40][40];
private static void detruire_element_instance() {
Scanner sc = new Scanner(System.in);
System.out.println("Quel ballon souhaitez-vous supprimer ?");
System.out.println("ligne du ballon : ");
String str4 = sc.nextLine();
System.out.println("Vous avez saisi : " + str4);
int i = Integer.parseInt(str4);
System.out.println("colone du ballon :");
String str5 = sc.nextLine();
System.out.println("Vous avez saisi : " + str5);
int j = Integer.parseInt(str5);
if(TableauBallon[i][j] == null){
System.out.println("Le ballon n'existe pas");
}
else{
TableauBallon[i][j] = null ;
System.out.println("Le ballon a ete supprime");
}
}
private static void afficher_instance() {
for (int x = 0 ; x < TableauBallon.length ; x++ ){
for (int y = 0 ; y < TableauBallon[0].length ; y++ )
{ try
{if (!(TableauBallon[x][y].getIdentificateur()== null)|
!(TableauBallon[x][y].getTaille()== 0))
System.out.println("ballon x>"+x+"ballon y>"+y
+"<id>"+ TableauBallon[x][y].getIdentificateur()
+"<dim>"+ TableauBallon[x][y].getTaille());
}
catch (Exception e) {
System.out.println("ballon x>"+x+"ballon y>"+y+"*****aucun ballon à afficher ");}
}
}
}
//////////////////////////////////////////////////////////
private static void creer_instance() {
System.out.println("Tapez les donnees du ballon :");
System.out.println("ligne du ballon : ");
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
System.out.println("Vous avez saisi : " + str1);
int i = Integer.parseInt(str1);
System.out.println("colone du ballon :");
String str2 = sc.nextLine();
System.out.println("Vous avez saisi : " + str2);
int j = Integer.parseInt(str2);
System.out.println("identificateur du ballon :");
String id = sc.nextLine();
System.out.println("Vous avez saisi : " + id);
System.out.println("taille du ballon :");
String str3 = sc.nextLine();
System.out.println("Vous avez saisi : " + str3);
int dim = Integer.parseInt(str3);
// il faut encore tester que le ballon ne soit pas créer endehors du tableau.
System.out.println("i>"+i+"<j>"+j+"<id>"+id+"<dim>"+dim);
TableauBallon[i][j] = new Ballon(id, dim) ;
}
public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int s = 1;
while ( s!=0){
System.out.println("+++++++++++++(MENU)+++++++++++++");
System.out.println("1) Créer un ballon");
System.out.println("2) Détruire un ballon");
System.out.println("3) Afficher la liste des ballons");
System.out.println("0) Quitter");
System.out.println("++++++++++++++++++++++++++++++++");
System.out.println("");
System.out.println("(Veuillez faire votre choix)");
String str1 = sc.nextLine();
System.out.println("Vous avez saisi : " + str1);
s= Integer.parseInt(str1);
switch (s) {
case 1 :
creer_instance();
break;
case 2 :
detruire_element_instance();
break;
case 3 :
afficher_instance();
break;
case 0 :
System.out.println("Au revoir !");
System.exit(0);
break;
}
}
}
}
Bonjour,
afficher dans un tableau java 10 entier et afficher le plus grand element et son indice.
merci davance
afficher dans un tableau java 10 entier et afficher le plus grand element et son indice.
merci davance
fulgenceong
Messages postés
1
Date d'inscription
jeudi 6 décembre 2007
Statut
Membre
Dernière intervention
6 décembre 2007
6 déc. 2007 à 19:19
6 déc. 2007 à 19:19
bonjour
je veux creer un tableau qui contient n elements et dont les valeurs seront saisies par l'utilisateur . je vous demande un coup de pouce
int tableau =new int [n]
int n
je ne sais pas si cette declaration est juste
j'ai un probleme avec la declarartion car la taille du tableau est une variable
Merci et bonne journee
je veux creer un tableau qui contient n elements et dont les valeurs seront saisies par l'utilisateur . je vous demande un coup de pouce
int tableau =new int [n]
int n
je ne sais pas si cette declaration est juste
j'ai un probleme avec la declarartion car la taille du tableau est une variable
Merci et bonne journee