Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAngjelin Malaj
5,983 PointsWrite a program that prints out Hello vertically! Dont use \n or multiple. Use loops style. Smb can help me please?
Its an assignment for me and i am getting confused
2 Answers
Stephen Shine
5,991 PointsUsing a for loop is a classic way of looping through an array. And remember that strings are an array of characters.
There's a useful function in Java to convert a string to an array of characters. You could then use the println method as part of the System class. Something like this:
String text = "Hello";
char[] textArray = text.toCharArray();
for (int i = 0; i < textArray.length; i++) {
System.out.println(textArray[i]);
}
Angjelin Malaj
5,983 PointsThank you Stephen Shine! it worked perfectly well