I need to output % in String.format . But this sign is forbidden to a conclusion. Tell me how to do this?

    3 answers 3

    We look in the documentation

     Conversion Argument category Description '%' percent The result is a literal '%' ('\u0025') 

    Those. to output the literal "%" you need to shield it with the same service character "%".

     System.out.println(String.format("10%%")); // 10% 
    • Thanks for the link to the documentation. - Vyacheslav Chernyshov

    Use %% I don’t know what else to add up to 30 characters of the message

      Use %% to help you.

       import java.util.*; import java.lang.*; import java.io.*; class StringFormatter { public static void main (String[] args) throws java.lang.Exception { System.out.printf(String.format("%s", "100%%")); } }