Problème Eclipse!

Résolu
Bonjour,

mon Eclipse n'exécute pas ce qu'il se trouve dans la boucle if..
est ce que quelqu'un a eu un problème pareil ?
ou sait ou est le problème??

Merci.

1 réponse

  1. Modérateur
    Je doute que ce soit la faute d'Eclipse, montre nous ton code pour te corriger (la partie avec le if devrait suffire)
    1. import java.util.Scanner;

      public class PremPass {
      public static void main(String []args){
      String label,operat,op1,op2;
      Instruction inst = new Instruction();

      System.out.println("entrez le label, S'il n y a pas de label écrivez //");
      Scanner sc= new Scanner(System.in);
      label=sc.next();
      System.out.println("entrez l'opération");
      operat=sc.next();
      if (operat=="add"){
      System.out.println("entrez les opérandes");
      op1=sc.next();
      op2=sc.next();
      inst=new Instruction(label,operat,op1,op2);}
      else
      if(operat=="stop") {
      inst=new Instruction(label,operat);
      }
      else
      if(operat=="copy"||operat=="divise"||operat=="load"||operat=="multi"||operat=="read"||operat=="sub"||operat=="store"||operat=="write"){
      System.out.println("entrez l'opérand");
      op1=sc.next();
      inst=new Instruction(label,ope,op1);
      }
      System.out.println(inst.label+" "+inst.operat+" "+inst.op1+" "+inst.op2);

      }
      }
    2. Modérateur
      if(operat=="stop")
      On ne compare jamais la valeur deux String avec l'opérateur == il faut utiliser la méthode equals.
      if (operat.equals("stop"))
      De même bien sûr pour tous tes tests suivants (qui seront forcément tous faux avec ==)
      if(operat=="copy"||operat=="divise"||operat=="load"||operat=="multi"||operat=="read"||operat=="sub"||operat=="store"||operat=="write")
    3. Oh! c'est vrai ! j'ai carrément oublier ça ^^" , Merciii KX