+ 1

How would I edit this to have a space between every two characters?

To begin with, I have an empty String then to that String characters of the UNICODE get added until the count has reached the number that I put in the parameter of the main method. After every 10 characters I want a line break and after the last character too. Now I have the code that fulfills this method but I want to add a space after every two characters, how do I do that? Code: public class Main { public static void main (String[] args) { //a String a = MoreMethods.createCharSeries('A', 30); System.out.println(a); } } public class MoreMethods { public static String createCharSeries (char startChar, int count) { String s = ""; for(int i = 1; i <= count; i++) { s = s + startChar++; //i = 10 if(i % 10 == 0) { s = s + "\n"; } } s = s + "\n"; return s; }

5th Mar 2018, 6:43 PM
Sebastian Sivertsen
Sebastian Sivertsen - avatar
5 Respostas
5th Mar 2018, 7:06 PM
Hannah Grace
Hannah Grace - avatar
+ 10
in for loop change your 1st line as: s=s + startChar++ + " "; // this will add space between 2 characters
5th Mar 2018, 6:50 PM
Hannah Grace
Hannah Grace - avatar
+ 2
Inside the loop, after s=s+startChar++ if(i%2 == 0) { s = s + " "; }
5th Mar 2018, 7:05 PM
Leonardo Medai Cossutta
Leonardo Medai Cossutta - avatar
+ 1
That did the trick to put a space after every character, but I want one after every second character? Thanks for your reply! :)
5th Mar 2018, 6:56 PM
Sebastian Sivertsen
Sebastian Sivertsen - avatar
+ 1
Yes exactly
5th Mar 2018, 7:04 PM
Sebastian Sivertsen
Sebastian Sivertsen - avatar