943,916 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6351
  • Java RSS
Sep 26th, 2007
0

Pattern Program help

Expand Post »
Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this:
123456
12345
1234
123
12
1

but when I try it, it goes like this:
654321
65432
6543
654
65
6

This is my program:
public class Patterns{
public static void main (String [] args) {

//set up for the rows

for(int row = 1 ; row <= 6; row++){

for (int num = 6; num >= row; num--){

System.out.print(num);
}
System.out.println();
}

}

}

Can anybody help please? thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
Dio1080 is offline Offline
47 posts
since Aug 2007
Sep 26th, 2007
-1

Re: Pattern Program help again

Ok I solved the last program, but I need on this one, I have no clue:

Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this:
123456
12345
1234
123
12
1

but when I try it, it goes like this:
123456
12345
1234
123
12
1

This is my program:
public class Patterns{
public static void main (String [] args) {

//set up for the rows

for(int row = 7 ; row > 1; row--){

for (int num = 1; num < row; num++){

System.out.print(num);
}
System.out.println();
}

}

}


Can anybody help please? thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
Dio1080 is offline Offline
47 posts
since Aug 2007
Sep 28th, 2007
0

Re: Pattern Program help

if you write the problem using code bbcode, it looks better...
you want something like
Java Syntax (Toggle Plain Text)
  1. 123456
  2. 12345
  3. 1234
  4. 123
  5. 12
  6. 1

There are different ways to solve this problem.
I would used a for loop to count how many empty spaces (" ") I need to print before I put the number. So that would increase from 0 to 5.. This way, it actually needed three for loops, and one counter based on what it would count how many space is needed.
Code would look something like:
Java Syntax (Toggle Plain Text)
  1. int counter=0;
  2. firstLoop: for() {
  3. secondLoop:for() {
  4. thirdLoop:for(0->counter){
  5. System.out.print(" ");
  6. }
  7. System.out.print(num);
  8. }
  9. System.out.println();
  10. counter++;
  11. }
Last edited by orko; Sep 28th, 2007 at 11:18 am.
Reputation Points: 46
Solved Threads: 11
Junior Poster
orko is offline Offline
164 posts
since Apr 2006
Jul 26th, 2009
0

Re: Pattern Program help

[COLOR="Green"]this:
123456
12345
1234
123
12
1



This is my program:
public class Patterns{
public static void main (String [] args) {

//set up for the rows

for(int row = 6 ; row >= 1; row++){

for (int num = 1; num <= row; num++){

System.out.print(num);
}
System.out.println();
}

}

}


where u frm?????
my id:chrsmnsn@gmail.com
Last edited by audioslave; Jul 26th, 2009 at 12:26 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
audioslave is offline Offline
1 posts
since Jul 2009
Jul 26th, 2009
0

Re: Pattern Program help

Click to Expand / Collapse  Quote originally posted by audioslave ...
[COLOR="Green"]this:
123456
12345
1234
123
12
1



This is my program:
public class Patterns{
public static void main (String [] args) {

//set up for the rows

for(int row = 6 ; row >= 1; row++){

for (int num = 1; num <= row; num++){

System.out.print(num);
}
System.out.println();
}

}

}


where u frm?????
my id:chrsmnsn@gmail.com

???? This post is years old, do u need help or you just wondering where I'm from?
Reputation Points: 10
Solved Threads: 0
Light Poster
Dio1080 is offline Offline
47 posts
since Aug 2007
Jul 13th, 2010
0

this is the solution for your pattern

class pattern
{
public static void main()
{
int i,j;
for(i=6;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}}}
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Megha SR is offline Offline
24 posts
since Jul 2010
Jul 13th, 2010
0

abcde pattern in for loop

can anyone solve this?
a b c d e d c b a
a b c d***d c b a
a b c*******c b a
a b***********b a
a***************a

NOTE: here '*' denotes space
Last edited by Megha SR; Jul 13th, 2010 at 10:16 am.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Megha SR is offline Offline
24 posts
since Jul 2010
Jul 31st, 2010
0
Re: Pattern Program help
hey megha SR
here is ur answer
class pattern
{
static void main()
{
int i,k,m,j,f,t;
for(i=0;i<4;i++)
{
m=4-i;
for(j=1,f=97;j<=m;j++,f++)
System.out.print((char)f);
for(t=1;t<=2*i;t++)
System.out.print(" ");
f=100-i;
for(k=m;k>0;k--,f--)
System.out.print((char)f);
System.out.println();
}
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nihalmn is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java Course Class
Next Thread in Java Forum Timeline: How to add another button





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC