+ 2

Result is blank, what now?

I made this program to find middle character in the string. But how can i change it if the result is blank space i want the program to write instead of blank space - # or something else, just not blank. https://code.sololearn.com/c2fLZt1Pn4NY/?ref=app

11th Oct 2018, 3:27 PM
Mateusz Legend
Mateusz Legend - avatar
5 odpowiedzi
+ 5
a space is a character so you could check the result with somthing like if(strResult.equals(" ")){System.out.print("The middle character is a space");}
11th Oct 2018, 3:50 PM
D_Stark
D_Stark - avatar
+ 4
Winter Wolf your welcome 😉👍
11th Oct 2018, 7:00 PM
D_Stark
D_Stark - avatar
+ 2
okay i made it kinda your way. u made me do it like this if(midChar(letters).equals(" ")){ System.out.println("The middle character is: space " + midChar(letters)); } else { System.out.println("The middle character is: " + midChar(letters)); } thanks a lot :)
11th Oct 2018, 4:28 PM
Mateusz Legend
Mateusz Legend - avatar
+ 1
i forget there can be 2x space if the string is even so it will be if(midChar(letters).equals(" ")) { System.out.println("The middle character is: space " + midChar(letters)); } else if (midChar(letters).equals(" ")) { System.out.println("The middle character is: space space" + midChar(letters)); } else { System.out.println("The middle character is: " + midChar(letters)); } } thank you
11th Oct 2018, 4:39 PM
Mateusz Legend
Mateusz Legend - avatar
+ 1
there are few options of results char char char space space space space char char space so i made that every space(" ") will be shown as # it was fun by working on this i made a lot of mistakes but finally got it thank you :) if(midChar(letters).equals(" ")) { System.out.println("The middle character is: " + midChar(letters).replace(' ', '#')); } else { System.out.println("The middle character is: " + midChar(letters).replace(' ', '#')); }
12th Oct 2018, 5:42 AM
Mateusz Legend
Mateusz Legend - avatar