Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Exercice 3.2 : Ecrivez une première fonction de nom toUpperCase qui prend une chaîne de caractères en argument et qui retourne une copie de cette chaîne mais avec toutes les lettres en majuscules.
  2.  
  3. public class exo3td2 {
  4. public static void main(final String[] args){
  5.  
  6. System.out.println(toUpperCase("bonjour tout le monde haha"));
  7. }
  8. public static String toUpperCase(String ch){ // exo 3.2
  9. int i;
  10. String rep = "";
  11. for(i=0;i<= ch.length();i++){
  12. char cl = ch.charAt(i); // isole le caractere a la position i
  13. if(cl>='a' && cl >='z'){
  14. char cm = (char) ((cl-'a') + 'A'); // les char sont rpz comme des entier on isole le char "cl" - 'a '(qui est un nombre dans la table ascii ) + A(le nombre ascii correspondant a la lettre A) pour avoir la maj
  15. rep = rep + cm; // concatenation pour avoir les maj
  16.  
  17. }
  18. else{
  19. return(rep + cl);
  20. }
  21. return(rep);
  22.  
  23. }
  24. }
  25. public static String append(String ch1, String ch2){ // exo 3.3
  26. return(ch1 + ch2);
  27. }
  28.  
  29.  
  30. }
  31.  
  32. erreur :
  33.  
  34. Exception in thread "main" java.lang.Error: Unresolved compilation problem:
  35. This method must return a result of type String
  36.  
  37. at exo3td2.toUpperCase(exo3td2.java:6)
  38. at exo3td2.main(exo3td2.java:4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement