472,341 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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:
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
Sep 27 '07 #1
12 2213
madhoriya22
252 100+
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:
Expand|Select|Wrap|Line Numbers
  1. public class Patterns{
  2. public static void main (String [] args) {
  3.  
  4. //set up for the rows
  5.  
  6. for(int row = 7 ; row > 1; row--){
  7.  
  8. for (int num = 1; num < row; num++){
  9.  
  10. System.out.print(num);
  11. }
  12. System.out.println();
  13. }
  14.  
  15. }
  16.  
  17. }
  18.  
Can anybody help please? thanks
Hi,
Please use code tags while posting code.
Your desired output and program output is same ... then what is the problem ?
Sep 27 '07 #2
I'm sorry, it must have typed it wrong, this is what I'm looking for:
123456
12345
1234
123
12
1
Sep 27 '07 #3
r035198x
13,262 8TB
I'm sorry, it must have typed it wrong, this is what I'm looking for:
123456

12345

1234

123

12

1
Have you written down your algorithm for this first?
Sep 27 '07 #4
algorithm? I don't think we learned that yet?
Sep 27 '07 #5
JosAH
11,448 Expert 8TB
algorithm? I don't think we learned that yet?
Main Entry: al·go·rithm
Pronunciation: 'al-g&-"ri-[th]&m
Function: noun
Etymology: alteration of Middle English algorisme, from Old French & Medieval
Latin; Old French, from Medieval Latin algorismus, from Arabic al-khuwArizmi,
from al-KhwArizmI fl A.D. 825 Islamic mathematician

: a procedure for solving a mathematical problem (as of finding the greatest
common divisor) in a finite number of steps that frequently involves repetition of
an operation; broadly : a step-by-step procedure for solving a problem or
accomplishing some end especially by a computer
kind regards,

Jos
Sep 27 '07 #6
Nepomuk
3,112 Expert 2GB
algorithm? I don't think we learned that yet?
An algorithm is similar to a recipe - instructions on how to do a job in loads of little steps.
For example, the algorithm to boil water may be:
  1. Make sure, you have a kitchen (if you don't, create one).
  2. Make sure, you have a pot (if you don't, create one).
  3. Make sure, you have a tap (if you don't, create one).
  4. Make sure, you have a oven (if you don't, create one).
  5. Go into the kitchen (may be complex, depending on your current position).
  6. Get a pot out of the shelves (may be more complex, e.g. if there are doors).
  7. Position the pot under the water tap (you may have to push it to one side before).
  8. Turn the tap on (there are loads of different taps).
  9. While the pot isn't full enough, keep checking, if the pot is full enough (you may want to take a break every time you've checked).
  10. When the pot is full, turn the tap off (same issue as turning it on).
  11. Lift the pot.
  12. Position the pot on the oven.
  13. Switch the oven on (depending on your type of oven, this could work in different ways).
  14. While the water isn't boiling, check if it's boiling.
I know, that is very detailed, but that's how you have to think when writing a program. A person would understand the command "boil water", but a computer needs all of these steps.

Greetings,
Nepomuk
Sep 27 '07 #7
JosAH
11,448 Expert 8TB
I know, that is very detailed, but that's how you have to think when writing a program. A person would understand the command "boil water", but a computer needs all of these steps.

Greetings,
Nepomuk
Two questions for a mathematician and a physicist

Question 1:

There's a bunsen burner, a book of matches a water tap and an empty kettle;
how to boil water?

Both the physicist and the mathematician come up with an identical answer:
open the tap, filll the kettle, close the tap again, put the kettle on the bunsen
burner, light it using the matches and wait.

Question 2:

There's a filled kettle positioned on the bunsen burner; how to boil water?

The physicist's answer: light the burner and wait.

The mathematician's answer: empty the kettle; now the problem is reduced to
the previous question.

kind regards,

Jos ;-)
Sep 27 '07 #8
Nepomuk
3,112 Expert 2GB
Two questions for a mathematician and a physicist

Question 1:

There's a bunsen burner, a book of matches a water tap and an empty kettle;
how to boil water?

Both the physicist and the mathematician come up with an identical answer:
open the tap, filll the kettle, close the tap again, put the kettle on the bunsen
burner, light it using the matches and wait.

Question 2:

There's a filled kettle positioned on the bunsen burner; how to boil water?

The physicist's answer: light the burner and wait.

The mathematician's answer: empty the kettle; now the problem is reduced to
the previous question.

kind regards,

Jos ;-)
Nice one! ^^
Sep 27 '07 #9
Ganon11
3,652 Expert 2GB
ERP! But once the kettle is empty, there's no specific mention of a tap? Where will the mathematician get the water? And besides, there aren't any matches.
Sep 27 '07 #10
JosAH
11,448 Expert 8TB
ERP! But once the kettle is empty, there's no specific mention of a tap? Where will the mathematician get the water? And besides, there aren't any matches.
Yep, you're right (bloody nitpickers ...) I should've defined both problems in a bit
more detail; but I hope you get the idea ;-)

kind regards,

Jos
Sep 27 '07 #11
Ganon11
3,652 Expert 2GB
(bloody nitpickers ...)
Wait, almost 50% of every post I've seen you make is nitpicking - you even admit so yourself on many occasions.
Sep 27 '07 #12
JosAH
11,448 Expert 8TB
Wait, almost 50% of every post I've seen you make is nitpicking - you even admit so yourself on many occasions.
That wasn't me.

kind regards,

Loretta ;-)
Sep 27 '07 #13

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

Similar topics

5
by: Drew | last post by:
We have a string like: 2004\05\05T00:00:00 We would like to remove all "\", any "-" and the T00:00:00 part of the string. The end result would...
3
by: kittykat | last post by:
Hi, I was wondering if you could help me. I am writing a program in C++, and the problem is, i have very limited experience in this language. I...
6
by: pitachu | last post by:
Hi, I'm not an expect in .NET, so would anyone know an answer a design pattern for the following? There are many customers that require minor...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use...
11
by: td0g03 | last post by:
Hello, I just have a few questions. The first one be how would you print a pattern. I could use the if else, but I remember my teacher talking about...
1
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation...
1
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation...
19
by: konrad Krupa | last post by:
I'm not expert in Pattern Matching and it would take me a while to come up with the syntax for what I'm trying to do. I hope there are some experts...
1
by: arunbs84 | last post by:
hi friends this is arun from coimbatore.i had written one program for pattern matching.That is ,the user have one file and after run his c program he...
7
by: NoviceJava | last post by:
Hey, I'm having trouble with an assignment and I need some help. basically, the assignment is the same as the from the following link:...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.