Advertisement
Guest User

ConvertLocalVariableToField

a guest
Oct 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package ConvertLocalVariableToField;
  2.  
  3. /**
  4. *
  5. * @author thao
  6. *
  7. * Code à refactorer
  8. *
  9. *
  10. * Type de refactor : Convert Local Variable To Field
  11. *
  12. *
  13. * Appliquer ce refactoring (menu Refactor > Convert Local Variable To Field) à :
  14. * - la ligne 26 pour la variable "k"
  15. * - la ligne 47 pour la variable "res"
  16. *
  17. *
  18. * Le but: On voudrait déplacer une déclaration d'une variable de l'intérieur d'une méthode vers le haut de la classe, où elle est ensuite visible par toute la classe.
  19. *
  20. *
  21. */
  22. public class Main {
  23.  
  24. /**
  25. * La fonction calcule la somme de 0 à 100
  26. * @return res
  27. */
  28. public static int toto() {
  29. int k = 100;
  30. int res = 0;
  31. for(int i = 0; i<k; i++) {
  32. res += i;
  33. }
  34. return res;
  35. }
  36.  
  37. public static void main(String[] args) {
  38. System.out.print("0 + 1 + 2 + ...+ 100 = " + toto());
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement