[SPOILER] Voici une proposition pour le palindrome
[SPOILER] Voici une proposition pour le palindrome
- Code:
public class Palindrome
{
final static char FINAL = '.';
final static char ESP = ' ';
public static void main(String [] arg)
{
char [] phrase;
boolean palindrome = false;
int nblett = 0;
phrase = Tab.saisirTab();
nblett = nblett(phrase, nblett);
//System.out.println("il y a : "+ nblett + " lettres dans ta phrase");
palindrome = verifpalindrome(phrase , nblett);
if (palindrome == true)
{
System.out.println("Oui c'est un palindrome");
}
else
{
System.out.println("Non ce n'est pas un palindrome");
}
}
private static boolean verifpalindrome(char[] phrase, int nblett)
{
int i = 0;
int j = i+nblett-1;
boolean palin = false;
do
{
i=i+1;
j=j-1;
}while ((i < j) && (phrase[i] == phrase[j]));
if (j>=i)
{
palin = false;
}
else
{
palin = true;
}
return palin ;
}
private static int nblett(char[] tab, int nblett)
{
int nblettre = 0;
int i = 0;
do
{
if (tab[i] != ESP)
{
nblettre = nblettre + 1;
i++;
}
else
i++;
} while (tab[i] != FINAL);
return nblettre;
}
}
GrlSidious (Vince)- Admin
- Messages : 58
Karma : 53
Date d'inscription : 23/05/2016
Age : 28
Localisation : Grenoble
Humeur : Fiora top 4 ever

» Proposition de covoiturage
» proposition pour la FVB
» Proposition pour un(e) aventurier(e) correspondant au profil
» Proposition pour les Bonus..!!
» Wilfried, une petite proposition pour toi !
» proposition pour la FVB
» Proposition pour un(e) aventurier(e) correspondant au profil
» Proposition pour les Bonus..!!
» Wilfried, une petite proposition pour toi !
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum