473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Matrix problem using loops

pattern--

*-----
**----
***---
****--
*****-
i tried here is what i have done please help me make it correct

Expand|Select|Wrap|Line Numbers
  1. class pattern
  2. {   
  3.     public void display()
  4.     {int i,j;
  5.  
  6.         for(i=1;i<=5;i++)
  7.         {
  8.             for(j=1;j<=i;j++)
  9.             {
  10.                 System.out.print("*");
  11.             }
  12.             System.out.println();
  13.         }
  14.     }
  15.  
  16.     public void displayer()
  17.     {int i,j;
  18.     for(i=1;i<=5;i++)
  19.         {
  20.             for(j=5;j>=i;j--)
  21.             {
  22.                 System.out.print("-");
  23.         }
  24.           System.out.println();
  25.         }
  26.     public static void main(String arg[]);
  27. {
  28.     pattern obj=new pattern();
  29.     obj.display();
  30.     obj.displayer();
  31. }
  32. }
  33. }
Apr 30 '14 #1
7 1578
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

You're already not using an array. But why would you want to do it without using loops?
Apr 30 '14 #2
i want you to help me make it correct by using loops only and thank u for viewing my post plzz help me do it
Apr 30 '14 #3
Rabbit
12,516 Expert Mod 8TB
You already are using loops. I don't understand your question.
Apr 30 '14 #4
stdq
94 64KB
If you want to simplify, you could do everything in main without using classes. Just use two loops, and two counters - it might help you if you name them with complete words, like row and column. Let's analyze the pattern:

* row 1 - column goes from 1 to 1, which equals row.
** row 2 - column goes from 1 to 2, which equals row.
*** row 3 - column goes from 1 to 3, which equals row.
**** row 4 - column goes from 1 to 4, which equals row.
***** row 5 - column goes from 1 to 5, which equals row.

So, the limit for the inner for loop depends on the current value of the counter for the outer loop, and you named these counters j and i, respectively.
Apr 30 '14 #5
yes but i have to print the under scores in oppsite directions too
May 1 '14 #6
yes i am using loops but if you and run this program in java(blue j) then it does not give the desired effect rabbit. i have tried it but it only print either the stars or the underscores plzz make this correct to print the pattern above
May 1 '14 #7
i got my answer thank you for viewing my post
thank you all
May 1 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
10
by: Pavan | last post by:
Hi i have two nested loops as shown below: 1. for(i=0;i<=1000;i++) { for(i=0;i<=100;i++) { .....; .....; }
9
by: cody | last post by:
for (int serie=1; serie < TurnierGruppe.AktuelleSerie.Serie; serie++) { //outer: here is works foreach (Tischbesetzung tb in TurnierGruppe.Serien.Tischebesetzungen) { for (int i=0;...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
1
by: alireza6485 | last post by:
I am a C# begginer.I have to write a program that asks the user to enter a word,then it encodes it and after encoding it ,it decodes it again(by using Arrays to make sure that weget the right...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.