?
Solved

Simple Java question

Posted on 2009-07-08
2
Medium Priority
?
214 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

800 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