What combination of characters can be used to reduce the writing of the symbols below? Console.WriteLine ("-------------------------")

    2 answers 2

    int n = 25; String str = new String('-',n); Console.WriteLine(str); 

    https://msdn.microsoft.com/ru-ru/library/system.string.string(v=vs.110).aspx

    • Thanks, @Valera! - olmar102

    In java for String there is no constructor with the task of the number of repetitions of a character. The en-SO shows an example traversal:

     String repeated = new String(new char[n]).replace("\0", s); n-число повторений s-строка, в вашем случае "-" 

    A string is created based on the char array, after which null in the array is replaced with your character.

    You can also use third-party libraries, for example, apache-commons

     System.out.println(StringUtils.repeat("-",4));