Les char en java

alffouss Messages postés 150 Statut Membre -  
 danimo -
Bonjour,
je veux savoir comment un peut dire en java : Prend le dernier caracter du mon qui commenrce par A

je sais comment prendre le dernier caractére du mot.Mais je ne sais pas comment on dit du mot qui commenrce par A.

voici le code que j'ai commencer":

package new2;

import java.io.IOException;
import java.io.InputStream;

class Ex {

public static void main(String[] args) {
identification();

}

public static void identification() {
String pm = "helli";

char nl =pm.charAt(pm.length() - 1);
{
System.out.println(nl);

}
}
}
Configuration: Windows XP Internet Explorer 6.0

1 réponse

  1. danimo
     
    Salut,

    String pm = "helli"; 
             
             if (pm.charAt(0) == 'A') // ou bien if (pm.startsWith("A"))
             {
                char nl =pm.charAt(pm.length() - 1);
                System.out.println(pm + " commence bien par A.");
                System.out.println("nl = " + nl);
             }
             else 
                System.out.println(pm + " ne commence pas par A.");


    Cordialement,

    Dan
    0