Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/01/2012, 11:55
Seisler
 
Fecha de Ingreso: febrero-2011
Mensajes: 83
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: Problema a la hora de imprimir un array

También he intentado modificarlo un poco declarando la array notas dentro del primer bucle, cuando relleno los datos y cambiando la forma de printarlos, así:

Código JAVA:
Ver original
  1. package exercicis.part5;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ProvaAlumne3 {
  6.     public static void main(String[] args) {
  7.        
  8.          
  9.         Alumne2 [] clase=new Alumne2 [2];
  10.        
  11.         Scanner entrada=new Scanner(System.in);
  12.        
  13.         String nom;
  14.         String cognoms;
  15.         int curs;
  16.        
  17.        
  18.        
  19.         for (int posicio=0;posicio<clase.length;posicio++) {
  20.            
  21.             System.out.print("Nom:");
  22.             nom=entrada.next();
  23.             System.out.print("Cognoms:");
  24.             cognoms=entrada.next();
  25.             System.out.print("Curs: ");
  26.             curs=entrada.nextInt();
  27.            
  28.              int[] notes = new int[6];
  29.            
  30.             for (int posicioNotes=0;posicioNotes<notes.length;posicioNotes++) {
  31.                 int nota=posicioNotes+1;
  32.                 System.out.print("Introdueix la nota (" +nota+"):");
  33.                 notes[posicioNotes]=entrada.nextInt();
  34.                
  35.                
  36.             }
  37.            
  38.            
  39.             clase[posicio]=new Alumne2(nom, cognoms, curs, notes);
  40.                        
  41.         }
  42.        
  43.         for (int posicio = 0; posicio < clase.length; posicio++) {
  44.                 System.out.println("\n\nL'alumne " + clase[posicio].nom + " " + clase[posicio].cognoms);
  45.                 System.out.println("del curs " + clase[posicio].curs);
  46.                 System.out.println("Te les seguents notes: ");
  47.                 for (int posicioNotes = 0; posicioNotes < clase[posicio].notes.length; posicioNotes++) {
  48.                     System.out.print(" " + clase[posicio].notes[posicioNotes]);
  49.  
  50.             }
  51.  
  52.  
  53.  
  54.         }
  55.        
  56.        
  57.     }
  58.    
  59. }