Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- public class exo3td2 {
- public static void main(final String[] args){
- System.out.println(toUpperCase("bonjour tout le monde haha"));
- }
- public static String toUpperCase(String ch){ // exo 3.2
- int i;
- String rep = "";
- for(i=0;i<= ch.length();i++){
- char cl = ch.charAt(i); // isole le caractere a la position i
- if(cl>='a' && cl >='z'){
- 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
- rep = rep + cm; // concatenation pour avoir les maj
- }
- else{
- return(rep + cl);
- }
- return(rep);
- }
- }
- public static String append(String ch1, String ch2){ // exo 3.3
- return(ch1 + ch2);
- }
- }
- erreur :
- Exception in thread "main" java.lang.Error: Unresolved compilation problem:
- This method must return a result of type String
- at exo3td2.toUpperCase(exo3td2.java:6)
- at exo3td2.main(exo3td2.java:4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement