Solved

Simple Java question

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
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.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now