Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - problema java con gli array tridimenzionali
Forum - Java - problema java con gli array tridimenzionali

Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 15:08
Lunedì, 17/09/2018
salve sto imparando gli array tridimenzionali in java ma ho un errore questo è il sorgente:
Codice sorgente - presumibilmente Java

  1. package com.pellegrinoprincipe;
  2.  
  3. class PrimoProgramma
  4. {
  5.         public static void main(String[] args)
  6.         {
  7.                 final String costante = "asd";
  8.                 String testo = "testo";
  9.                 int numero = 1;
  10.                 System.out.println(testo + numero + "prova");
  11.                 for(int i = 0; i <= 10; i++)
  12.                 {
  13.                         System.out.println(testo + numero + "prova");
  14.                 }
  15.          int a = 1;
  16.          int b = 2;
  17.          boolean c = 1 > 2;
  18.          if(c == false)
  19.          {
  20.                 System.out.println("falso");
  21.          }
  22.          System.out.println(c);
  23.          int [1][2][3] asd = {{1,2,3}, {4,5,6}, {7,8,9}};
  24.          for(int x = 0; 0 <= asd[1].lenght; x++)
  25.          {
  26.                 System.out.println(asd[1][x]);
  27.          }
  28.         }
  29. }



e questo l' errore

Codice sorgente - presumibilmente Plain Text

  1. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:24: error: ';' expected
  2.          asd = {{1,2,3}, {4,5,6}, {7,8,9}};
  3.                                     ^


PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6402
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 15:55
Lunedì, 17/09/2018
... tridimensionali con la s ...

Quello ti sembra un array a tre dimensioni?

Semmai

int [][][] cubo = {
{ { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },
{ { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },
{ { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },
};

Ultima modifica effettuata da nessuno il 17/09/2018 alle 16:00


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 13:44
Sabato, 22/09/2018
il nuovo sorgente è questo
Codice sorgente - presumibilmente Java

  1. package com.pellegrinoprincipe;
  2.  
  3. class PrimoProgramma
  4. {
  5.         public static void main(String[] args)
  6.         {
  7.                 final String costante = "cubo";
  8.                 String testo = "testo";
  9.                 int numero = 1;
  10.                 System.out.println(testo + numero + "prova");
  11.                 for(int i = 0; i <= 10; i++)
  12.                 {
  13.                         System.out.println(testo + numero + "prova");
  14.                 }
  15.          int a = 1;
  16.          int b = 2;
  17.          boolean c = 1 > 2;
  18.          if(c == false)
  19.          {
  20.                 System.out.println("falso");
  21.          }
  22.          System.out.println(c);
  23.          int [][][] cubo = {{ { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },
  24.                                                 { { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },
  25.                                                 { { 1, 2, 3 },{ 1, 2, 3 },{ 1, 2, 3 } },};
  26.          for(int x = 0; 0 <= cubo[].lenght; x++)
  27.          {
  28.                 System.out.println(cubo[0][x]);
  29.          }
  30.         }
  31. }



ma ottengo quest errore:

Codice sorgente - presumibilmente Java

  1. javac '/home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java'
  2. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:26: error: class expected
  3.          for(int x = 0; 0 <= cubo[].lenght; x++)
  4.                                     ^


PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6402
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 20:34
Sabato, 22/09/2018
Ma che vorresti fare con quella for ?

E poi, scusami, ma se parliamo di TRE dimensioni, perché continui a scrivere

cubo[0][x]

??

Comunque dai un'occhiata a questo video di base

https://www.youtube.com/watch?v=mIJXeNWIE1E

Ultima modifica effettuata da nessuno il 22/09/2018 alle 20:39


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 14:57
Mercoledì, 03/10/2018
ho guardato il video e questo è il mio sorgente solo che mi da errore:
Codice sorgente - presumibilmente Java

  1. package com.pellegrinoprincipe;
  2.  
  3. class PrimoProgramma
  4. {
  5.         public static void main(String[] args)
  6.         {
  7.                 String nome = "nino";
  8.                 switch(nome)
  9.                 {
  10.                         case "nino":
  11.                         System.out.println("nino");
  12.                         break;
  13.                         case "pippo":
  14.                         System.out.println("pippo");
  15.                         break;
  16.                         default:
  17.                         System.out.println("default");
  18.                 }
  19.                 String a[] = {"nino", "pippo", "gabriella"};
  20.                 for(String elem : a)
  21.                 {
  22.                         System.out.println(elem);
  23.                 }
  24.                 String array [] [] [] = new String ["nino"] ["pippo"] ["gabriella"];
  25.                 for(int i=0; i < array.lenght; i++)
  26.                 {
  27.                         for(int j=0; j<array[i].lenght; j++)
  28.                         {
  29.                                 for(int k=0; k < array[j].lenght; k++)
  30.                                 {
  31.                                         System.out.println(array[i][j][k]);
  32.                                 }
  33.                         }
  34.  
  35.                 }
  36.         }
  37. }



quest errore:
Codice sorgente - presumibilmente Java

  1. utente@ubuntupc:~/Scrivania$ javac '/home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java'
  2. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:24: error: incompatible types: String cannot be converted to int
  3.                 String array [] [] [] = new String ["nino"] ["pippo"] ["biella"];
  4.                                                     ^
  5. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:24: error: incompatible types: String cannot be converted to int
  6.                 String array [] [] [] = new String ["nino"] ["pippo"] ["biella"];
  7.                                                              ^
  8. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:24: error: incompatible types: String cannot be converted to int
  9.                 String array [] [] [] = new String ["nino"] ["pippo"] ["biella"];
  10.                                                                        ^
  11. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:25: error: cannot find symbol
  12.                 for(int i=0; i < array.lenght; i++)
  13.                                       ^
  14.   symbol:   variable lenght
  15.   location: variable array of type String[][][]
  16. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:27: error: cannot find symbol
  17.                         for(int j=0; j<array[i].lenght; j++)
  18.                                                ^
  19.   symbol:   variable lenght
  20.   location: class String[][]
  21. /home/utente/Scrivania/com/pellegrinoprincipe/PrimoProgramma.java:29: error: cannot find symbol
  22.                                 for(int k=0; k < array[j].lenght; k++)
  23.                                                          ^
  24.   symbol:   variable lenght
  25.   location: class String[][]
  26. 6 errors



grazie delle risposte :)

PM Quote
Avatar
TheDarkJuster (Member)
Guru^2


Messaggi: 1620
Iscritto: 27/09/2013

Segnala al moderatore
Postato alle 20:49
Mercoledì, 03/10/2018
Io credo che tu deve fermarti e riflettere sul tuo codice.
Quando hai riflettuto sul codice leggi gli errori del compilatore e prova ad interpretarli. Sappi che quegli errori sono destinati a te, non a noi. Sono la ragione per cui non è possibile compilare il programma, e dovresti seriamente rifletterci su per poter imparare qualcosa.

PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 14:15
Lunedì, 24/12/2018
salve, scusare se resumo questo vecchio topic ma sono stato all ospedale psichiatrico in tsv. io rifletto ma non capisco perfavore potreste darmi un codice di esempio che sia giusto? così forse capisco è che mi sono inmantanato negli array e mi tormentano il cervello che non riesco a farli

PM Quote