954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pattern Program help

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

Dio1080
Light Poster
47 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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

Dio1080
Light Poster
47 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

if you write the problem using code bbcode, it looks better...
you want something like

123456
 12345
  1234
   123
    12
     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:

int counter=0;
firstLoop: for() {
  secondLoop:for() {
    thirdLoop:for(0->counter){
      System.out.print(" ");
    }
    System.out.print(num);
  }
  System.out.println();
  counter++;
}
orko
Junior Poster
164 posts since Apr 2006
Reputation Points: 46
Solved Threads: 11
 

[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

audioslave
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

[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?

Dio1080
Light Poster
47 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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();
}}}

Megha SR
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 3
 

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

Megha SR
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 3
 

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();
}
}
}

nihalmn
Newbie Poster
1 post since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You