Monday, 28 December 2020

Initializing a string with repeated character of specific length

Source code:

import java.util.*;

import java.io.*;

public class Main

{

public static void main(String[] args) 

{

   char c='0';

            int n=10;

  char ch[]=new char[n];

  Arrays.fill(ch,c);

  String s=new String(ch);

  System.out.println(s);   

}

}

output:
0000000000

No comments:

Post a Comment

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...