473,692 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pattern Program help

5 New Member
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.prin t(num);
}
System.out.prin tln();
}

}

}


Can anybody help please? thanks
Sep 27 '07 #1
12 2400
madhoriya22
252 Contributor
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
Dio1080
5 New Member
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 MVP
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
Dio1080
5 New Member
algorithm? I don't think we learned that yet?
Sep 27 '07 #5
JosAH
11,448 Recognized Expert MVP
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 Recognized Expert Specialist
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 Recognized Expert MVP
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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

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

Similar topics

5
1708
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 pattern it will match on everything except the final T00 part.
3
5108
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 I want my program to search a text file for this pattern, and let the user know if this pattern exists or not. So far, i have figured out how to make my prgram read the text file, but i'm not sure how to take the information the user inserts...
6
2329
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 developing. I would like to reuse the majority of the functionality of this program since each customer is only requiring certain changes to this program.
34
11184
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 snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
11
2620
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) printf($); Code below will take the size of what I input and change the size of the pattern by adding more or less $
1
1729
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 had no connection or reference to the object that triggered it. It goes something like this: (not syntactically correct..it's just for the idea)
1
4157
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 had no connection or reference to the object that triggered it. It goes something like this: (not syntactically correct..it's just for the idea)
19
3170
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 /d/d/d/s/d/d in any text. There could be spaces in front or after the pattern (the nnn nn could be without spaces also) but it shouldn't pick it up in case like this 1234 56768
1
2599
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 in file the line number will be print.but my program checks only first two lines.it will not check other lines.i am trying to find out the prob.plz anybody help me to find wat wrong in my program. thanking u. the program is: #include<stdio.h>...
7
2110
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 However, there is one major exception: The pattern is reversed. Here is what it looks like: If the user types "3", your program should produce the following output: ***
0
8544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8810
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5821
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4325
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2977
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1961
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.