[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Simple Java question

Posted on 2009-07-08
2
Medium Priority
?
218 Views
Last Modified: 2013-11-23
This seems like such a simple question but I'm not finding the solution easily.  

I'm learning java right now and am trying to build a simple asci image with "\" that increases in size by 1 for each new line.  

Below is the for loop that I've created.  

Any ideas greatly appreciated.  
System.out.print("\\");
for (int space =1; space <= (1 * line); space++) {
     System.out.print ("");
}

Open in new window

0
Comment
Question by:jenieh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 500 total points
ID: 24808527
Here's is how i would write such a program. You pretty much need to have two loops. One for the lines and then one to output character in each line.
class Sample
{
	public static void main(String[] args)
	{
		int lineCount = 10;
 
		for(int line = 1; line <= lineCount; line++)
		{
			for(int i = 0; i < line; i++)
				System.out.print("\\");
 
			System.out.println("");
		}
	}
}

Open in new window

0
 
LVL 2

Author Comment

by:jenieh
ID: 24808560
Excellent!  Thank you.  Kept trying to force it without a second loop.  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question