How to use String.format() with integers in Java

2 Answers

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            String result = String.format("%d %d %d", 3, 99, 1255);
            System.out.println(result);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
3 99 1255
  
 */

 



answered Nov 19, 2016 by avibootz
0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            String result = String.format("%d\n%d\n%d\n", 3, 99, 1255);
            System.out.println(result);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
3
99
1255
  
 */

 



answered Nov 19, 2016 by avibootz

Related questions

...