473,378 Members | 1,438 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,378 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 2370
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 be 20040505. I know that if I use as the...
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 would like my user to enter a specific pattern, and...
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 customizations to the program I will be...
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 standard enums? There's now a nice little code...
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 something like for(i=1;i<=size;i) ...
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 where I needed to catch an event in an object that...
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 where I needed to catch an event in an object that...
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 that can help me. I'm trying to match...
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 pass some text command line, if the text is found...
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: http://www.thescripts.com/forum/thread607498.html ...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.