Pattern Program help

Reply

Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Pattern Program help

 
0
  #1
Sep 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Re: Pattern Program help again

 
0
  #2
Sep 26th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: Pattern Program help

 
0
  #3
Sep 28th, 2007
if you write the problem using code bbcode, it looks better...
you want something like
  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:
  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.
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: audioslave is an unknown quantity at this point 
Solved Threads: 0
audioslave audioslave is offline Offline
Newbie Poster

Re: Pattern Program help

 
0
  #4
Jul 26th, 2009
[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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Re: Pattern Program help

 
0
  #5
Jul 26th, 2009
Originally Posted by audioslave View Post
[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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC