Solved

Simple Java question

Posted on 2009-07-08
2
201 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 136
jmss example java 2 33
How to configure empty element in XML Document parser? 15 45
Eclipse with various Java releases 7 51
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

726 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