import java.util.*; public class FormatDemo { public static void main(String args[]) { Formatter fmt = new Formatter(); fmt.format("Formatting %s is easy %d %f", "with Java", 10, 98.6); System.out.println(fmt); } } |
A voir sur le mêm Sujet
-
Méthode ‘printf’: Comment définir l’alignement de sortie
{filelink=6012} public class AlignementSortie { public static void main(String[] argv) throws Exception { System.out.printf(“%15s %15s %15s”, “Un”, “Simple”, “Exemple !”); } }
-
Comment formater les valeurs Hexadécimales
{filelink=6034} import java.util.Date; public class PrintfExamples { public static void main(String[] args) { //hex value is b5151397, B5151397 System.out.printf(“hex value is %1$h, %1$H”, new Date() …
-
Afficher la date en format choisi par l’utilisateur
{filelink=5548} import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Date; public class DateFormatUtilisateur { /** date du Jour */ Date dNow = new Date(); …
-
Comment Formater l’heure et la date à l’aide de la classe « Formatter »
{filelink=4418} import java.util.Calendar; import java.util.Formatter; public class MainClass { public static void main(String args[]) { Formatter fmt = new Formatter(); Calendar cal = Calendar.getInstance(); // …
-
Exemple des boîtes de dialogue d’entrée et de sortie
{filelink=3433} import javax.swing.JOptionPane; // Importer le package // des boîtes de dialogue public class ExempleJDialog { public static void main( String args[] ) { // …
-
MessageFormat: Formater un message
{filelink=5925} import java.text.MessageFormat; public class ExempleFomat { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { “Fred”, “Jhon”, “Peter” }; …
-
MessageFormat: Formater un nombre à virgule
{filelink=5927} import java.text.MessageFormat; public class NombreVirgule { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Double(3.14), new Double(1234.56) …
-
Classe Formatter: Exemple de la table des carrés et des cubes
{filelink=5760} import java.util.Formatter; public class ExempleCarreCube { public static void main(String args[]) { Formatter fmt; for (int i = 1; i
-
Classe ‘MessageFormat’: Formater un Message qui contient un Nombre
{filelink=5924} import java.text.MessageFormat; public class ExempleMsgFormat2 { public static void main(String[] argv) throws Exception { Object[] params = new Object[] { new Integer(1939), new Integer(1945) …
-
Exemple d’utilisation des mots clés ‘break’ et ‘continue’ dans une même boucle
{filelink=4319} public class BreakEtContinue { public static void main(String[] args) { for(int i = 0; i < 100; i++) { if(i == 74) break; // ...