How to use formatted string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = String.format("line1 \nline2 \nline3: %s\nline4: %d" , "Java", 31);  

        System.out.println(str);
    }
}
 
 
 
 
/*
run:
 
line1 
line2 
line3: Java
line4: 31

*/

 



answered Apr 1, 2021 by avibootz
edited May 26, 2024 by avibootz

Related questions

3 answers 255 views
1 answer 190 views
2 answers 255 views
1 answer 138 views
1 answer 170 views
1 answer 142 views
...