Solved

Simple Java question

Posted on 2009-07-08
2
197 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
2 Comments
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 125 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.

789 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