java - Accessing a returned value from a different case -


hi it's 3rd time i'm posting question on forum , no 1 has been capable enlighten me situation.

i pasted code matters here , try explain in best can ...

methods:

  1. showmenu(in) - show's menu list calls choice(in)
  2. choice(in) - accepts in input through -> getnumber(in)
  3. getnumber(in) - number returned , selects correct case

now i'm dealing case 1: , case 2:

case 1:

  1. string clef = assigned return value saisirclef(in)
  2. saisirclef(in); method returns string after completing logic
  3. showmenu(in) needed can pick different case

case 2: simple i'm trying access string after has been completed in case 1; if not should go through case 1

can done ? feel everytime gets passed break variables dissapear normal ?

how can ?

public static void choice(scanner in){      switch(getnumber(in)){         case 1:             string clef = saisirclef(in);             showmenu(in);             break;         case 2:             if(clef.isempty()){                 system.out.println("erreur : aucune clef n’a été saisie.");                 saisirclef(in);             }             else{                 afficherclef(clef);             }             break;         case 3:             chiffrerfichier();             break;         case 4:             dechiffrerfichier();             break;         case 5:             quitapplication();             break;         default:             system.out.println("default");             break;         }     } 

try this:

private static string clef = null;  public static void choice(scanner in){      switch(getnumber(in)){         case 1:             clef = saisirclef(in);             showmenu(in);             break;         case 2:             if(clef == null || clef.isempty()){                 system.out.println("erreur : aucune clef n’a été saisie.");                 clef = saisirclef(in);             }             else{                 afficherclef(clef);             }             break;                     // ...     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -