Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 22nd, 2005, 03:08 PM
handy handy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 handy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 26 m 15 sec
Reputation Power: 0
Lucky Dip Lotto Ticket code!!!!

Please can someone help with code for a little programme Iam trying to write in Java.
Iam having trouble with the sort feature, iam using a bubble sort.
code as follows:-

// Method : Sort 6 numbers in ascending order

public void sortNumbers()
{
for(int next = 0; next < lottoNumber.length-1; next++){
for (int other = next +1; other < lottoNumber.length; other++){
if(lottoNumber [next] > lottoNumber [other])
int temp = lottoNumber [other];
lottoNumber [other] = lottoNumber [next];
lottoNumber [next] = temp;
next = -1;
}

}
[img]images/buttons/edit.gif[/img]

Reply With Quote
  #2  
Old March 22nd, 2005, 07:25 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 331 Viper_SB User rank is Private First Class (20 - 50 Reputation Level)Viper_SB User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 4 h 53 m 7 sec
Reputation Power: 6
moved to Java Development

Reply With Quote
  #3  
Old March 23rd, 2005, 08:52 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Code:
public void sortNumbers() {
	for(int next = 0; next < lottoNumber.length-1; next++) {
		for (int other = next +1; other < lottoNumber.length; other++) {
			if(lottoNumber [next] > lottoNumber [other])
				int temp = lottoNumber [other];

			lottoNumber [other] = lottoNumber [next];
			lottoNumber [next] = temp;
			next = -1;
		}
	}

After properly indenting your code, I noticed you're missing a closing bracket.
Also, you don't have brackets around your IF statement, was that intended?
In doing this, only the first statement will execute when the IF statement is true.

I haven't analyzed your logic, just your syntax.
Hopefully that's a start.

Note: The code in my post is the exact same as yours... if you copy&paste this code, you'll need to add that final closing bracket.

Reply With Quote
  #4  
Old March 23rd, 2005, 10:06 AM
handy handy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 handy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 26 m 15 sec
Reputation Power: 0
Print Method for Lotto

thank you for your help, the bracket was in the wrong place and should have enclosed the if statement, changed and there is no syntax errors now ))

I now need to add a print method // Method : Format and display 6 numbers to the screen. I belive i use the original for loop add a print method, am i correct, perhaps you can give me some guidance. No ticket is generated yet from the code i have input, i take it this will happen when i add a print method??

Regards

Handy

Reply With Quote
  #5  
Old March 23rd, 2005, 11:51 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I've based this on your earlier example...
Try something like this:
Code:
public void printNumbers() {
	for(int next = 0; next < lottoNumber.length-1; next++) {
		System.out.println("Number " + next + ": " + lottoNumber [next]);
	}
}

Reply With Quote
  #6  
Old March 23rd, 2005, 03:03 PM
handy handy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 handy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 26 m 15 sec
Reputation Power: 0
Reply to print method

Quote:
Originally Posted by MadCowDzz
I've based this on your earlier example...
Try something like this:
Code:
public void printNumbers() {
	for(int next = 0; next < lottoNumber.length-1; next++) {
		System.out.println("Number " + next + ": " + lottoNumber [next]);
	}
}


do i not have to use a forloop? for the print method

Reply With Quote
  #7  
Old March 23rd, 2005, 03:31 PM
handy handy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 8 handy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 26 m 15 sec
Reputation Power: 0
Lotto program help required

My sort method is not working, code as follows. I also have a problem with the
amount of numbers being generated, I require 6 random numbers, but I am getting
about 30 and some repeats too. Does anyone have any ideas please.

// Method : Sort 6 numbers in ascending order

public void sortNumbers()
{
for(int next = 0; next < lottoNumber.length-1; next++)
for (int other = next +1; other < lottoNumber.length; other++)
if(lottoNumber [next] > lottoNumber [other]){
int temp = lottoNumber [other];
lottoNumber [other] = lottoNumber [next];
lottoNumber [next] = temp;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Lucky Dip Lotto Ticket code!!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT