Grosse MàJ
This commit is contained in:
6
workspace/Palindrome/.classpath
Normal file
6
workspace/Palindrome/.classpath
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
17
workspace/Palindrome/.project
Normal file
17
workspace/Palindrome/.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Palindrome</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
BIN
workspace/Palindrome/iutsud/Assertion$InvariantException.class
Normal file
BIN
workspace/Palindrome/iutsud/Assertion$InvariantException.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
workspace/Palindrome/iutsud/Assertion.class
Normal file
BIN
workspace/Palindrome/iutsud/Assertion.class
Normal file
Binary file not shown.
219
workspace/Palindrome/iutsud/Assertion.java
Normal file
219
workspace/Palindrome/iutsud/Assertion.java
Normal file
@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (C) 1997 Roger Whitney <whitney@cs.sdsu.edu>
|
||||
*
|
||||
* This file is part of the San Diego State University Java Library.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
package iutsud ;
|
||||
|
||||
|
||||
/**
|
||||
* Cette classe imite la macro ASSERT de C/C++.
|
||||
* Elle permet de s'assurer qu'une condition est v<>rifi<66>e
|
||||
* avant de poursuivre l'ex<65>cution.<p>
|
||||
* Elle a trois m<>thodes
|
||||
* statiques : <code>pre</code>, <code>post</code> et <code>invariant</code>
|
||||
* Ces m<>thodes sont identiques. Chaque m<>thode arr<72>te l'ex<65>cution du
|
||||
* programme en levant une exception si son argument est faux. <p>
|
||||
* Un exemple d'utilisation d'assertion est :
|
||||
* <pre>
|
||||
* <code>Assertion.pre( (mois == 1 ) && ( jour <= 31 ));</code>
|
||||
* </pre>
|
||||
* Ceci v<>rifie que la condition est vrai <20> ce stade de l'ex<65>cution.
|
||||
* Si elle n'est pas v<>rifi<66>e, une exception de type
|
||||
* <code>Assertion.PreConditionException</code>,
|
||||
* <code>Assertion.PostConditionException</code>
|
||||
* ou <code>Assertion.InvariantException</code>
|
||||
* est lev<65>e.
|
||||
* Ces exceptions d<>rivent de <code>RuntimeException</code>
|
||||
* et arr<72>tent l'ex<65>cution du programme en affichant
|
||||
* l'<27>tat de la pile d'ex<65>cution. <P>
|
||||
* Cette classe provient de la classe <code>sdsu.io.Assert</code> de l'universit<69>
|
||||
* de San Diego (<a href="http://www.eli.sdsu.edu/java-SDSU">http://www.eli.sdsu.edu/java-SDSU</a>).
|
||||
* <p>Les modifications sont mineures :
|
||||
* <li> d<>finition et utilisation d'exceptions internes <20> la classe
|
||||
* <li> suppression de la m<>thode <code>condition</code>
|
||||
* <li> m<>thode <code>classInvariant</code> renomm<6D>e <code>invariant</code>
|
||||
* <li> classe <code>Assert</code> renomm<6D>e <code>Assertion</code>
|
||||
*/
|
||||
/*
|
||||
* <p> This class is modeled after the ASSERT macro in C/C++. The class
|
||||
* has three static methods.
|
||||
* The methods are identical. Each method will throw an exception if
|
||||
* is argument is false. A sample use of the assert is:
|
||||
* <pre>
|
||||
* Assert.pre( (X > 5 ) && ( Z <= 10 ));
|
||||
* </pre>
|
||||
* This asserts that the condition should be true at this point.
|
||||
* If it is not an exception will be thrown. So the program can
|
||||
* assume that the condition is true after the above assert. <P>
|
||||
* In C/C++ ASSERT is defined as a macro. Thus the macro can be
|
||||
* turned off with a compile switch. This allows the code to contain
|
||||
* ASSERTS with out any runtime cost. There is no way in Java to
|
||||
* completely eliminate the cost of the Assert calls. Hopefully
|
||||
* future compilers will be smart enough to use tricks with
|
||||
* classpaths and two versions of this class to "turn off" the
|
||||
* Assert calls in productin code without modifing the program
|
||||
* source.<P>
|
||||
* See <I>Writing Solid Code</I> by Steve Maguire, pp 13-44
|
||||
* or <I>Object-Oriented Software Construction</I> by
|
||||
* Bertrand Meyer, pp 111 - 163 for the use and importance
|
||||
* of Assert.
|
||||
*
|
||||
* @see sdsu.test.AssertException
|
||||
* @version 1.0 30 December 1997
|
||||
* @author Roger Whitney
|
||||
* (<a href=mailto:whitney@cs.sdsu.edu>whitney@cs.sdsu.edu</a>)
|
||||
*/
|
||||
|
||||
public abstract class Assertion
|
||||
{
|
||||
|
||||
private Assertion()
|
||||
{
|
||||
super() ;
|
||||
}
|
||||
|
||||
// /* main de test
|
||||
|
||||
private static void main(String args[]) {
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.print( "Print a Boolean ");
|
||||
boolean b = Console.readBoolean() ;
|
||||
pre(b) ;
|
||||
post(b) ;
|
||||
invariant(b) ;
|
||||
}
|
||||
}
|
||||
// */
|
||||
|
||||
/**
|
||||
* Exception lev<65>e lorsqu'une pr<70>condition n'est pas v<>rifi<66>e
|
||||
*/
|
||||
|
||||
public static class PreConditionException extends RuntimeException
|
||||
{
|
||||
public PreConditionException(String message)
|
||||
{
|
||||
super(message) ;
|
||||
}
|
||||
} // end class PreConditionException
|
||||
|
||||
/**
|
||||
* Exception lev<65>e lorsqu'une postcondition n'est pas v<>rifi<66>e
|
||||
*/
|
||||
|
||||
public static class PostConditionException extends RuntimeException
|
||||
{
|
||||
public PostConditionException(String message)
|
||||
{
|
||||
super(message) ;
|
||||
}
|
||||
} // end class PostConditionException
|
||||
|
||||
/**
|
||||
* Exception lev<65>e lorsqu'un invariant n'est pas v<>rifi<66>e
|
||||
*/
|
||||
|
||||
public static class InvariantException extends RuntimeException
|
||||
{
|
||||
public InvariantException(String message)
|
||||
{
|
||||
super(message) ;
|
||||
}
|
||||
} // end class InvariantException
|
||||
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>PreConditionException</code>
|
||||
* @param cond la condition <20> v<>rifier
|
||||
*/
|
||||
|
||||
public static void pre( boolean cond )
|
||||
{
|
||||
if ( !cond )
|
||||
throw new PreConditionException( "Pr<EFBFBD>condition non v<>rifi<66>e" );
|
||||
}
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>PreConditionException</code>
|
||||
* avec le message pass<73> en param<61>tre
|
||||
* @param cond la condition <20> v<>rifier
|
||||
* @param message message <20> afficher
|
||||
*/
|
||||
|
||||
public static void pre( boolean cond , String message )
|
||||
{
|
||||
if ( !cond )
|
||||
throw new PreConditionException( message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>PostConditionException</code>
|
||||
* @param cond la condition <20> v<>rifier
|
||||
*/
|
||||
|
||||
public static void post( boolean cond )
|
||||
{
|
||||
if ( !cond )
|
||||
throw new PostConditionException( "Postcondition non v<>rifi<66>e" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>PostConditionException</code>
|
||||
* avec le message pass<73> en param<61>tre
|
||||
* @param cond la condition <20> v<>rifier
|
||||
* @param message message <20> afficher
|
||||
*/
|
||||
|
||||
public static void post( boolean cond , String message)
|
||||
{
|
||||
if ( !cond )
|
||||
throw new PostConditionException( message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>InvariantException</code>
|
||||
* @param cond la condition <20> v<>rifier
|
||||
*/
|
||||
|
||||
public static void invariant( boolean cond )
|
||||
{
|
||||
if ( !cond )
|
||||
throw new InvariantException( "Invariant non v<>rifi<66>" );
|
||||
}
|
||||
/**
|
||||
* Arr<72>te l'ex<65>cution du programme si la condition n'est pas v<>rifi<66>e
|
||||
* en levant l'exception <code>InvariantException</code>
|
||||
* avec le message pass<73> en param<61>tre
|
||||
* @param cond la condition <20> v<>rifier
|
||||
* @param message message <20> afficher
|
||||
*/
|
||||
|
||||
public static void invariant( boolean cond , String message )
|
||||
{
|
||||
if ( !cond )
|
||||
throw new InvariantException( message );
|
||||
}
|
||||
|
||||
}
|
BIN
workspace/Palindrome/iutsud/Console$ConvertionException.class
Normal file
BIN
workspace/Palindrome/iutsud/Console$ConvertionException.class
Normal file
Binary file not shown.
BIN
workspace/Palindrome/iutsud/Console$ReadException.class
Normal file
BIN
workspace/Palindrome/iutsud/Console$ReadException.class
Normal file
Binary file not shown.
BIN
workspace/Palindrome/iutsud/Console.class
Normal file
BIN
workspace/Palindrome/iutsud/Console.class
Normal file
Binary file not shown.
649
workspace/Palindrome/iutsud/Console.java
Normal file
649
workspace/Palindrome/iutsud/Console.java
Normal file
@ -0,0 +1,649 @@
|
||||
package iutsud ;
|
||||
|
||||
import java.io.BufferedReader ;
|
||||
import java.io.InputStreamReader ;
|
||||
|
||||
/**
|
||||
* Cette classe fournit des m<>thodes simples pour lire les types
|
||||
* de base sur l'entr<74>e standard (au clavier).<p>
|
||||
* La lecture est faite par des instructions du type :
|
||||
* <pre><code> int i = Console.<b>readInt()</b> ;
|
||||
* double d = Console.<b>readDouble()</b> ;
|
||||
* char c = Console.<b>readChar()</b> ;
|
||||
* ...</code> </pre>
|
||||
*
|
||||
* <li>Le principe g<>n<EFBFBD>ral est de lire ligne par ligne et de ne traiter
|
||||
* qu'une seule donn<6E>e par ligne.
|
||||
* <li>En cas d'erreur le programme est arr<72>t<EFBFBD> en levant une exception ;
|
||||
* il affiche alors un message d'erreur ainsi que le contenu de la pile d'ex<65>cution.
|
||||
* <li>L'introduction d'une ligne vide provoque une erreur sauf pour <code>readChar()</code>
|
||||
* qui renvoie le caract<63>re de fin de ligne <code>'\n'</code>, et sauf pour <code>readLine()</code>
|
||||
* qui renvoie la cha<68>ne vide.
|
||||
* <li>La rencontre de la fin de fichier (Ctrl-D au clavier) est g<>n<EFBFBD>ralement
|
||||
* consid<69>r<EFBFBD>e comme une erreur sauf pour <code>readLine()</code> qui renvoie <code>null</code>.
|
||||
* <p>
|
||||
* Le point de d<>part a <20>t<EFBFBD> la classe <code>sdsu.io.Console</code> de l'universit<69>
|
||||
* de San Diego (<a href="http://www.eli.sdsu.edu/java-SDSU">http://www.eli.sdsu.edu/java-SDSU</a>).
|
||||
* Cette classe a <20>t<EFBFBD> simplifi<66>e pour r<>pondre <20> nos besoins particuliers pour
|
||||
* l'enseignement de l'introduction <20> l'algorithmique.
|
||||
* Le code a <20>t<EFBFBD> enti<74>rement remani<6E> pour utiliser les fonctions de
|
||||
* conversion du langage Java.
|
||||
* Des am<61>liorations pourraient certainement y <20>tre apport<72>es en utilisant
|
||||
* la classe <code>Number</code> notamment pour les probl<62>mes d'internationalisation,
|
||||
* li<6C>s <20> l'<27>criture des nombres en <b>virgule</b> flottante.
|
||||
* <p>
|
||||
*
|
||||
* <b>Utilisation</b> : <p>
|
||||
* <li>Le fichier <code>Console.class</code> se trouve sous le r<>pertoire
|
||||
* <code>/usr/local/lib/java/iutsud</code>.
|
||||
* <li>La variable <code>CLASSPATH</code> doit contenir
|
||||
* <code>/usr/local/lib/java</code>. Sur <i>sterne</i> elle est initialis<69>e
|
||||
* automatiquement au d<>marrage de la session avec cette valeur.
|
||||
* <li>Les classes utilisatrices doivent importer la classe
|
||||
* <code>Console</code> depuis le package <code>iutsud</code> par l'instruction
|
||||
* <code>import iutsud.Console</code>
|
||||
*
|
||||
*
|
||||
* <p>Le document de pr<70>sentation peut <20>tre g<>n<EFBFBD>r<EFBFBD> depuis le source par la commande : <br>
|
||||
* <code> javadoc -version -author iutsud</code>
|
||||
* @author Raymond Schneider
|
||||
* (<a href=mailto:Raymond.Schneider@iutsud.u-strasbg.fr>Raymond.Schneider@iutsud.u-strasbg.fr</a>)
|
||||
* @version version 0.1 17/07/98
|
||||
*/
|
||||
|
||||
public class Console {
|
||||
|
||||
private static BufferedReader cin = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
System.in )) ;
|
||||
|
||||
|
||||
private static void main(String args[]) {
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.print( "Print a Base ");
|
||||
int base = Console.readInt() ;
|
||||
System.out.print( "Print a Long in base " + base + " : ") ;
|
||||
long lb = Console.readLong(base) ;
|
||||
System.out.println( "You typed: " + lb );
|
||||
|
||||
System.out.print( "Print a Byte ");
|
||||
byte k = Console.readByte() ;
|
||||
System.out.println( "You typed: " + k );
|
||||
|
||||
System.out.print( "Print a Short ");
|
||||
int j = Console.readShort() ;
|
||||
System.out.println( "You typed: " + j );
|
||||
|
||||
System.out.print( "Print a Int ");
|
||||
int i = Console.readInt() ;
|
||||
System.out.println( "You typed: " + i );
|
||||
|
||||
System.out.print( "Print a Long ");
|
||||
long l = Console.readLong() ;
|
||||
System.out.println( "You typed: " + l );
|
||||
|
||||
System.out.print( "Print a Float ");
|
||||
float f = Console.readFloat() ;
|
||||
System.out.println( "You typed: " + f );
|
||||
|
||||
System.out.print( "Print a Double ");
|
||||
double d = Console.readDouble() ;
|
||||
System.out.println( "You typed: " + d );
|
||||
|
||||
System.out.print( "Print a Boolean ");
|
||||
boolean b = Console.readBoolean() ;
|
||||
System.out.println( "You typed: " + b );
|
||||
|
||||
System.out.print( "Print a Char ");
|
||||
char c = Console.readChar() ;
|
||||
System.out.println( "You typed: " + c );
|
||||
}
|
||||
}
|
||||
|
||||
private Console()
|
||||
{
|
||||
super() ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception lev<65>e lors d'une erreur de lecture
|
||||
*/
|
||||
|
||||
public static class ReadException extends RuntimeException
|
||||
{
|
||||
public ReadException(String message)
|
||||
{
|
||||
super(message) ;
|
||||
}
|
||||
} // end class ReadException
|
||||
|
||||
/**
|
||||
* Exception lev<65>e lors d'une erreur de conversion
|
||||
*/
|
||||
|
||||
public static class ConvertionException extends RuntimeException
|
||||
{
|
||||
public ConvertionException(String message)
|
||||
{
|
||||
super(message) ;
|
||||
}
|
||||
} // end class ConvertionException
|
||||
|
||||
|
||||
/**
|
||||
* Quitte le programme en levant l'exception e
|
||||
* Le syst<73>me affichera<72> le message d'erreur associ<63>
|
||||
* ainsi que la pile d'ecx<63>cution
|
||||
* @param e l'exception <20> lever
|
||||
*/
|
||||
|
||||
/*
|
||||
* Exits programs after throwing an exception
|
||||
* @param e exception to be thrown
|
||||
*/
|
||||
|
||||
static final void exitProgram( RuntimeException e )
|
||||
{
|
||||
throw e ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quitte le programme suite <20> une erreur de conversion ;
|
||||
* affiche un message d'erreur en levant l'exception
|
||||
* <code>Console.ConvertionException</code>
|
||||
* @param s la cha<68>ne <20> convertir
|
||||
* @param t le type vers lequel il fallait convertir
|
||||
*/
|
||||
|
||||
/*
|
||||
* Exits programs after displaying a conversion error message
|
||||
* and after dumping the Thread's stack
|
||||
* @param s String that could not be converted
|
||||
* @param t Conversion Destination Type
|
||||
*/
|
||||
|
||||
private static final void conversionError( String s , String t )
|
||||
{
|
||||
exitProgram( new ConvertionException(
|
||||
conversionErrorMessage( s , t ) ) ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quitte le programme suite <20> une erreur de lecture ;
|
||||
* affiche un message d'erreur en levant l'exception
|
||||
* <code>Console.ReadException</code>
|
||||
* @param s la raison de l'erreur <20> afficher
|
||||
* @param t le type lu
|
||||
*/
|
||||
|
||||
/*
|
||||
* Exits programs after displaying a conversion error message
|
||||
* and after dumping the Thread's stack
|
||||
* @param s the error cause
|
||||
* @param t Read Destination Type
|
||||
*/
|
||||
|
||||
private static final void readError( String s , String t )
|
||||
{
|
||||
exitProgram( new ReadException ( s + " lors de la lecture d'un " + t) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose le message d'erreur <20> afficher suite <20> une erreur de conversion ;
|
||||
* @param s la cha<68>ne <20> convertir
|
||||
* @param t le type vers lequel il fallait convertir
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bulids a conversion error message
|
||||
* @param s String that could not be converted
|
||||
* @param t Conversion Destination Type
|
||||
*/
|
||||
|
||||
private static String conversionErrorMessage( String s, String t )
|
||||
{
|
||||
return '"' + s + '"' + " ne peut <20>tre convertie en " + t ;
|
||||
}
|
||||
|
||||
// Input methods ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Lit une valeur bool<6F>enne dans une ligne.
|
||||
* Lit une ligne et d<>termine si elle repr<70>sente <code>true</code> ou <code>false</code>.
|
||||
* Les valeurs possibles sont : <i>true</i> and <i>false</i>,
|
||||
* <i>vrai</i> and <i>faux</i>.
|
||||
* La comparaison est insensible <20> la casse (majuscule, minuscule).
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur de lecture ou en fin de fichier
|
||||
* @return la valeur bool<6F>ene correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII boolean value.
|
||||
* It reads a word and determines if it represents <code>true</code> or
|
||||
* <code>false</code>. Possible values are: <i>true</i> and <i>false</i>,
|
||||
* <i>vrai</i> and <i>faux</i>.
|
||||
* The comparison is case insensitive.
|
||||
* Program exits on read errors or EOF
|
||||
* @return the boolean.
|
||||
*/
|
||||
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
boolean b = false ;
|
||||
String s ;
|
||||
|
||||
s= readLine("boolean") ;
|
||||
|
||||
if (s.equalsIgnoreCase(String.valueOf(false))
|
||||
|| s.equalsIgnoreCase("faux") )
|
||||
b= false;
|
||||
|
||||
else if (s.equalsIgnoreCase(String.valueOf(true))
|
||||
|| s.equalsIgnoreCase("vrai") )
|
||||
b= true;
|
||||
|
||||
else
|
||||
conversionError( s , "boolean" ) ;
|
||||
|
||||
return b;
|
||||
|
||||
} // end readBoolean
|
||||
|
||||
/**
|
||||
* Lit un caract<63>re dans une ligne.
|
||||
* La ligne lue doit contenir au maximum un caract<63>re.
|
||||
* Si la ligne est vide le caract<63>re <code>'\n'</code> est renvoy<6F>.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur de lecture ou en fin de fichier
|
||||
* ou encore si la ligne contenait plusieurs caract<63>res.
|
||||
* @return le caract<63>re lu ou <code>'\n'</code> si la ligne <20>tait vide.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads one ASCII character and convert it into the internal <code>char</code>
|
||||
* format. If the line is empty <code>'\n'</code> is returned.
|
||||
* If more than one character are available in the line, only the first one is returned ; all other are
|
||||
* ignored.
|
||||
* Program exits on read errors or EOF or if more characters are available
|
||||
* @return the character or <code>'\n'</code> if line was empty.
|
||||
*/
|
||||
|
||||
public static char readChar()
|
||||
{
|
||||
String s ;
|
||||
char c = '\n' ;
|
||||
|
||||
s= readNewLine("char");
|
||||
|
||||
if (s.length() == 1)
|
||||
c= s.charAt(0);
|
||||
else if ( s.length() != 0 )
|
||||
exitProgram( new ReadException(
|
||||
"La ligne lue contenait plus d'un caract<63>re : "
|
||||
+ '"' + s + '"' + '\n' )
|
||||
);
|
||||
|
||||
return c ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un nombre en virgule flottante et en double pr<70>cision dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>double</code> en Java et permettre la conversion par :
|
||||
* <code>Double(String).doubleValue()</code>
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>double</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal floating point number.
|
||||
* A floating point number should obey Java String conversion :
|
||||
* <code>Double(String).doubleValue()</code>
|
||||
* Program exits on read errors or EOF
|
||||
* @return the double.
|
||||
*/
|
||||
|
||||
public static double readDouble()
|
||||
{
|
||||
String s ;
|
||||
double d = 0.0 ;
|
||||
|
||||
s= readLine("double");
|
||||
|
||||
try
|
||||
{
|
||||
d = new Double(s).doubleValue() ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, "double");
|
||||
}
|
||||
|
||||
return d ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un nombre en virgule flottante et en simple pr<70>cision dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>float</code> en Java et permettre la conversion par :
|
||||
* <code>Float(String).floatValue()</code>
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>float</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal floating point number.
|
||||
* A floating point number should obey Java String conversion :
|
||||
* <code>Float(String).floatValue()</code>
|
||||
* Program exits on read errors or EOF
|
||||
* @return the double.
|
||||
*/
|
||||
|
||||
public static float readFloat()
|
||||
{
|
||||
String s ;
|
||||
float f = 0.0F ;
|
||||
|
||||
s= readLine("float");
|
||||
|
||||
try
|
||||
{
|
||||
f = new Float(s).floatValue() ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, "float" );
|
||||
}
|
||||
|
||||
return f ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un nombre entier dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>int</code> en Java et permettre la conversion par :
|
||||
* <code>Integer.parseInt(String)</code>.
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>int</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal integer conforming to <code>Integer.parseInt(String)</code>.
|
||||
* Integers can be preceded by optional whitespace (SPACE or TAB).
|
||||
* Program exits on read errors or EOF
|
||||
* @return the integer.
|
||||
*/
|
||||
|
||||
public static int readInt()
|
||||
{
|
||||
int i = 0 ;
|
||||
String s ;
|
||||
|
||||
s= readLine("int");
|
||||
|
||||
try
|
||||
{
|
||||
i = Integer.parseInt(s) ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, "int" );
|
||||
}
|
||||
|
||||
return i ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un nombre entier long <20>crit en base <code>b</code> dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>long</code> en Java et permettre la conversion par :
|
||||
* <code>Long.parseLong(String,b)</code>
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @param b la base dans laquelle l'entier lu est exprim<69>
|
||||
* @return la valeur <code>long</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII long expressed in base <code>b</code> and conforming
|
||||
* to <code>Long.parseLong(String,b)</code>
|
||||
* Longs can be preceded by optional whitespace (SPACE or TAB).
|
||||
* Program exits on read errors or EOF
|
||||
* @param b the numbering base used to make the conversion
|
||||
* @return the long.
|
||||
*/
|
||||
|
||||
public static long readLong(int b)
|
||||
{
|
||||
long l = 0L;
|
||||
String s ;
|
||||
String t = "long" ;
|
||||
|
||||
if ( b != 10)
|
||||
t= t + " in base " + b ;
|
||||
|
||||
s= readLine(t);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
l = Long.parseLong(s, b) ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, t) ;
|
||||
}
|
||||
|
||||
return l ;
|
||||
|
||||
}
|
||||
/**
|
||||
* Lit un nombre entier long dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>long</code> en Java et permettre la conversion par :
|
||||
* <code>Long.parseLong(String)</code>
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>long</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal long conforming to <code>Long.parseLong(String)</code>
|
||||
* Longs can be preceded by optional whitespace (SPACE or TAB).
|
||||
* Program exits on read errors or EOF
|
||||
* @return the long.
|
||||
*/
|
||||
|
||||
public static long readLong()
|
||||
{
|
||||
return readLong(10) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un nombre entier court dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>short</code> en Java et permettre la conversion par :
|
||||
* <code>Short.parseShort(String)</code>
|
||||
* Le nombre peut tre pre<72>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>short</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal short.
|
||||
* Shorts can be preceded by optional whitespace (SPACE or TAB).
|
||||
* Program exits on read errors or EOF
|
||||
* @return the short.
|
||||
*/
|
||||
|
||||
public static short readShort()
|
||||
{
|
||||
short j = 0 ;
|
||||
String s = readLine("short");
|
||||
|
||||
try
|
||||
{
|
||||
j = Short.parseShort(s) ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, "short" );
|
||||
}
|
||||
|
||||
return j ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un octet dans une ligne.
|
||||
* Ces nombres doivent <20>tre conforme <20> l'<27>criture standard des constantes
|
||||
* <code>byte</code> en Java et permettre la conversion par :
|
||||
* <code>Byte.parseByte(String)</code>
|
||||
* Le nombre peut <20>tre pr<70>c<EFBFBD>d<EFBFBD> ou suivi d'un nombre quelconque d'espaces
|
||||
* (SPACE ou TAB). La ligne lue ne doit comporter qu'un seul nombre.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur ou en fin de fichier
|
||||
* @return la valeur <code>byte</code> correspondante.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads an ASCII decimal byte.
|
||||
* Bytes can be preceded by optional whitespace (SPACE or TAB).
|
||||
* Program exits on read errors or EOF
|
||||
* @return the byte.
|
||||
*/
|
||||
|
||||
public static byte readByte()
|
||||
{
|
||||
byte b = 0 ;
|
||||
String s = readLine("byte");
|
||||
|
||||
try
|
||||
{
|
||||
b = Byte.parseByte(s) ;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
conversionError( s, "byte" );
|
||||
}
|
||||
|
||||
return b ;
|
||||
|
||||
}
|
||||
/**
|
||||
* Lit une ligne.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur de lecture.
|
||||
* @return une cha<68>ne indiquant le contenu de la ligne ou
|
||||
* une cha<68>ne vide lorsque la ligne <20>tait vide ou
|
||||
* <code>null</code> en fin de fichier .
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads a line.
|
||||
* Program exits on read errors
|
||||
* @return the line content or an empty string if nothing entered or <code>null</code> if EOF reached .
|
||||
*/
|
||||
|
||||
public static String readLine()
|
||||
{
|
||||
String s = null ;
|
||||
|
||||
try
|
||||
{
|
||||
s= cin.readLine();
|
||||
}
|
||||
catch ( java.io.EOFException error)
|
||||
{
|
||||
s = null ;
|
||||
}
|
||||
catch ( Exception error )
|
||||
{
|
||||
exitProgram( new RuntimeException(error.toString()) ) ;
|
||||
}
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit une nouvelle ligne.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur de lecture ou si la fin de fichier
|
||||
* est rencontr<74>e.
|
||||
* @param t cha<68>ne indiquant le type de la donn<6E>e lue dans cette ligne
|
||||
* @return une cha<68>ne indiquant le contenu de la ligne ou
|
||||
* une cha<68>ne vide lorsque la ligne <20>tait vide .
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads a new line.
|
||||
* Program exits on read errors or if EOF is reached.
|
||||
* @param t String indicating the type expected in the line
|
||||
* @return the line content or an empty string if nothing entered .
|
||||
*/
|
||||
|
||||
private static String readNewLine(String t)
|
||||
{
|
||||
String s ;
|
||||
|
||||
s= readLine() ;
|
||||
|
||||
if ( s == null)
|
||||
readError ( " Fin de fichier inattendue" , t) ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit une donn<6E>e de type <code>t</code> dans une ligne non vide.
|
||||
*
|
||||
* Le programme stoppe en cas d'erreur de lecture, de fin de fichier
|
||||
* ou si la ligne <20>tait vide.
|
||||
* @param t cha<68>ne indiquant le type de la donn<6E>e lue dans cette ligne
|
||||
* @return une cha<68>ne indiquant le contenu non vide de la ligne.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Reads a data of type <code>t</code> in a non empty line.
|
||||
* Program exits on read errors or EOF or if line is empty
|
||||
* @param t String indicating the type expected in the line
|
||||
* @return the non empty line content
|
||||
*/
|
||||
|
||||
private static String readLine(String t)
|
||||
{
|
||||
String s ;
|
||||
|
||||
s= readNewLine(t).trim() ;
|
||||
|
||||
if (s.length() == 0)
|
||||
readError ( " Ligne vide" , t) ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end class Console
|
BIN
workspace/Palindrome/palindrome/Palindrome.class
Normal file
BIN
workspace/Palindrome/palindrome/Palindrome.class
Normal file
Binary file not shown.
75
workspace/Palindrome/palindrome/Palindrome.java
Normal file
75
workspace/Palindrome/palindrome/Palindrome.java
Normal file
@ -0,0 +1,75 @@
|
||||
package palindrome;
|
||||
|
||||
import iutsud.Console;
|
||||
import java.lang.*;
|
||||
|
||||
public class Palindrome {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
StringBuffer arguments = new StringBuffer();
|
||||
String texte;
|
||||
int longueurArguments = args.length;
|
||||
|
||||
for(int i=0; i<longueurArguments; i++)
|
||||
{
|
||||
arguments.append(args[i]);
|
||||
}
|
||||
texte = arguments.toString();
|
||||
System.out.println(texte);
|
||||
if(estUnPalindrome(texte) == true)
|
||||
{
|
||||
System.out.println(texte + " est un palindrome de longueur " + texte.length() + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(texte + " n'est pas un palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean estUnPalindrome(String chaine)
|
||||
{
|
||||
boolean resultat = true;
|
||||
int longueurChaine;
|
||||
int avanceDeb = 0;
|
||||
int reculeFin;
|
||||
chaine = chaine.toUpperCase();
|
||||
char char1;
|
||||
char char2;
|
||||
|
||||
longueurChaine = chaine.length();
|
||||
reculeFin = longueurChaine - 1;
|
||||
|
||||
while(avanceDeb <= reculeFin && resultat == true)
|
||||
{
|
||||
char1 = chaine.charAt(avanceDeb);
|
||||
char2 = chaine.charAt(reculeFin);
|
||||
/* while(Character.isWhitespace(char1))
|
||||
{
|
||||
avanceDeb++;
|
||||
char1 = chaine.charAt(avanceDeb);
|
||||
}
|
||||
while (Character.isWhitespace(char2))
|
||||
{
|
||||
reculeFin++;
|
||||
char2 = chaine.charAt(reculeFin);
|
||||
}*/
|
||||
System.out.print("Lettre d<>but : " + chaine.charAt(avanceDeb));
|
||||
System.out.println(" Lettre fin : " + chaine.charAt(reculeFin));
|
||||
resultat = false;
|
||||
if (chaine.charAt(avanceDeb) == chaine.charAt(reculeFin))
|
||||
{
|
||||
resultat = true;
|
||||
}
|
||||
avanceDeb++;
|
||||
reculeFin--;
|
||||
}
|
||||
|
||||
return resultat;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user