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:
- showmenu(in) - show's menu list calls choice(in)
- choice(in) - accepts in input through -> getnumber(in)
- getnumber(in) - number returned , selects correct case
now i'm dealing case 1: , case 2:
case 1:
- string clef = assigned return value saisirclef(in)
- saisirclef(in); method returns string after completing logic
- 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
Post a Comment