Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StringFormat
- {
- public static void main(String[] args)
- {
- String first = "first";
- int dato1 = 400;
- double dato2 = 0.567;
- String second = "second";
- int dato3 = 1;
- double dato4 = 300.5123456789;
- //A la derecha los numeros
- String format1 = String.format("%-15s%15d%15.4f", first, dato1, dato2);
- String format2 = String.format("%-15s%15d%15.4f", second, dato3, dato4);
- System.out.println(format1);
- System.out.println(format2);
- //A la izquierda los numeros
- System.out.println();
- format1 = String.format("%-15s%-15d%-15.4f", first, dato1, dato2);
- format2 = String.format("%-15s%-15d%-15.4f", second, dato3, dato4);
- System.out.println(format1);
- System.out.println(format2);
- /* Output:
- *
- * first 400 0,5670
- * second 1 300,5123
- *
- * first 400 0,5670
- * second 1 300,5123
- *
- * */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement