Let me explain. Say I have a given array of integers:
public static void spacing(String str)
int[] spacing = new int[]{1, 2, 3, 2, 1};
//Some function to find the given number in
//the array and coverts to the equal number of spaces
for (int i = 0; i < str.length(); i++)
System.out.println((the method for spacing) + str.charAt(i));
public static void main(String[] args)
spacing("Wow!!");
I understand it is not formatted properly. I just copied the gist over so you can get an idea of what I am wondering. How can I convert those given integers into the same number of spaces?
(Meaning 1 would print 1 space, 2 would print 2 spaces, 3 spaces, etc...)
Is it possible to print the space character spacing[i]
times?
Edited: I am limited to only importing java.utils.Arrays
java.lang
I have also updated the text to show how it needs to produce a pattern. I have also tried some of the answer provided, however it is still not printing the correct number of spaces.
I have tried converting the int array to a char array and using Array.fill and while it fills the array with spaces, it's only one space per array value (instead of 2 having 2 spaces, it puts 1 space for each value). My program is supposed to take characters from the user (which it already does) I am just having trouble getting the array to print the proper number of spaces before each character.
This is how the expected result looks if the user enters "Wow!!":
W
o
w
!
!