Probleme execution

svp j'ai ecrit un programme et une fois j'arrive à l'etape d'execution de l'ajout des nouveaux points le programme me genere un erreurs qui peux m'aider et me dire c quoi le probleme en mon code et merc i
voila le code :
package main2;
import java.util.Scanner;
import pack2.Point;
public class Exercice2_2 
{
 private static Scanner S;

 public static void main(String[] args) 
 {
  Point [] T ;
  int m ;
  int N ;
  boolean trouve;
  S = new Scanner ( System.in);
  System.out.println("donner la taille de tableau ");
  N=S.nextInt();
  T=new Point [N];
  
  for (int i=0 ; i<N ; i++)
  {
   T[i]=new Point() ;
   T[i].saisie();
  }
  
        for(int i=0 ; i<N ; i++)
        {
         T[i].afficher();
         
        }
        
        System.out.println("saisir un point") ; 
         Point A = new Point () ; 
         A.saisie(); 
         trouve = false ;
         int j=0 ;
         while ((j<N)&&(!trouve))
          if (T[j].comparer(A))
           trouve=true ;
          else 
           j++;
         if(trouve)
          System.out.println("point trouvée");
         else 
          System.out.println("point non trouvée");
         
         System.out.println("donnez le nombre des points à ajouter");
         m=S.nextInt() ;
          Point [] t2 =new Point[N+m] ;
         // deplacer les elements de t1 dans t2 
          for (int i =0 ;i<N; i++)
          {
           t2[i]=T[i] ;
          }
           for(int i=0 ;i<m ; i++)
           {
            t2[j+m] = new Point() ;
            t2[j+m].saisie() ;
           }
        }
 }

2 réponses

  1. Modérateur
    Bonjour,

    Quelle est l'erreur, et à quoi ressemble ta classe Point ?
    1. voila la clase point :
      package pack2;

      import java.util.Scanner;

      public class Point
      {
      private int x ;
      private int y ;
      private Scanner S ;

      public void initialiser (int a , int b)
      {
      x=a ;
      y=b ;
      }

      public void saisie()
      {
      S= new Scanner(System.in);
      System.out.println("saisir x ");
      x=S.nextInt() ;
      System.out.println("saisir y ");
      y=S.nextInt() ;

      }

      public void afficher()
      {
      System.out.println("x : "+x+" y :"+y);
      }

      public void deplacer(int dx , int dy)
      {
      x+=dx ;
      y+=dy ;
      }

      public void copier(Point P)
      {
      x=P.x ;
      y=P.y ;
      }

      public boolean comparer (Point P)
      {
      return ((x==P.x) && (y==P.y));
      }
      }

      et voila l'erreur qui s'affiche :
      donner la taille de tableau
      2
      saisir x
      2
      saisir y
      5
      saisir x
      6
      saisir y
      8
      x : 2 y :5
      x : 6 y :8
      saisir un point
      saisir x
      2
      saisir y
      1
      point non trouvée
      donnez le nombre des points à ajouter
      3
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
      at main2.Exercice2_2.main(Exercice2_2.java:56)