How to replace a string to a set of one characters

  • A+
Category:Languages

How do I replace an inputted string word to a set of one character: For example:

The string is: Hello Word The output should be: aaaaa aaaa

The space should remain a space.

I've tried this one but there's no space.

Scanner input = new Scanner(System.in); String word =  input.nextLine();  for(int i = 0; i < word.length(); i++){                      System.out.print("a"); } 

 


Perhaps

System.out.println("Hello Word".replaceAll("//S", "a")); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: