IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Collection et Stream Java Discussion :

Comment créer un array à deux dimensions avec une boucle


Sujet :

Collection et Stream Java

  1. #1
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2009
    Messages
    736
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2009
    Messages : 736
    Points : 1 101
    Points
    1 101
    Par défaut Comment créer un array à deux dimensions avec une boucle
    Bonjour,
    Est ce que quelqu'un peut me dire comment affecter les valeurs d'un array en deux dimension avec un boucle, voici un exemple avec un remplissage manuel.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    float[] myIntArray = new float[]{1.2, 2.5, 3.4, 7.9, 8.6};
     
    private float getRandom(float[] array) {
    	int rnd = new Random().nextInt(array.length);
    	return array[rnd];
    }
     
    private float[][] getArray() {
            int k = 300;
    	float positions[][] = new float[][] {
    			//{X coordinate, Y Coordinate}
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    			{ k = k + 300, getRandom(myIntArray) },
    	};
    	return column_positions;
    }
    A la recherche d'un film : http://chercher-un-film.com

  2. #2
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,


    Tout simplement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	private float[][] getArray() {
    		final float[][] positions = new float[7][2];
    		int k = 300;
    		for (float[] row : positions) {
    			row[0] = (k = k + 300);
    			row[1] = getRandom(myIntArray);
    		}
    		return positions;
    	}
    a++

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2009
    Messages
    736
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2009
    Messages : 736
    Points : 1 101
    Points
    1 101
    Par défaut
    Merci !
    A la recherche d'un film : http://chercher-un-film.com

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 29/06/2011, 17h33
  2. Réponses: 0
    Dernier message: 04/05/2011, 14h50
  3. Comment passer un tableau à deux dimensions dans une fonction
    Par Niko_de_bordo dans le forum Débuter
    Réponses: 2
    Dernier message: 02/07/2009, 15h15
  4. comment créer un array js à partir d'une requête PHP Mysql
    Par tavarlindar dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 17/08/2008, 23h29
  5. Comment créer un site immobilier dynamique avec une base de données ?
    Par Alain troverti dans le forum Général Conception Web
    Réponses: 14
    Dernier message: 07/07/2006, 21h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo