Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 4th, 2008, 05:37 AM
Glasgow_Man Glasgow_Man is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 8 Glasgow_Man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 50 sec
Reputation Power: 0
Highest/Lowest Int values

Hi,

Can you help with a simple yet puzzling piece of code.

I'm new to programming and I'm using the while loop.

I'm entering all different ints values plus I'm terminating when I get to '0'.

I full understanding how to add up all the int values.

However if I enter three different int values how do I display the highest or lowest value alone?

Code below:

Code:

public class HighNumber {
	public static void main(String[] args) {


Int sum = 0; 
Int aNumber = -1;

While (aNumber=!0) // is not 0 java code!

	aNumber = JFB.getInt("Type a number, please (0 to stop):"); 
	sum =  sum + aNumber:}

JFB.display("The highest number is" + sum );	

}

}


The code is in java but it can be switched to C++ or vbscript.

Any feedback would be greatly appreciated.

Reply With Quote
  #2  
Old November 4th, 2008, 07:48 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 47th Plane (28000 - 28499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,432 Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 1 Day 1 h 1 m 6 sec
Reputation Power: 2190
--moved to the general Programming forum. what made you post in VB forum??

anyway, to do what you want, you have to work with variables,
remembering the highest and lowest value.
Code:
Int sum = 0; 
Int aNumber = -1;
Int max = -999999;
Int min = 999999;

While (aNumber != 0)
{
	aNumber = JFB.getInt("Type a number, please (0 to stop):"); 
	if (aNumber != 0)
	{
		sum =  sum + aNumber;
		if (aNumber > max)
			max = aNumber;
		if (aNumber < min)
			min = aNumber;
	}
}

JFB.display("The highest number i s" + max );
JFB.display("The lowest number is " + min );
JFB.display("The sum is " + sum );

hope this is clear enough, let me know if not..

Reply With Quote
  #3  
Old November 4th, 2008, 03:28 PM
Glasgow_Man Glasgow_Man is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 8 Glasgow_Man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 50 sec
Reputation Power: 0
Thanks it worked

cheers Shadow wizard code works! ..... ps you have exquisite taste in ladies my friend.


Quote:
Originally Posted by Shadow Wizard
--moved to the general Programming forum. what made you post in VB forum??

anyway, to do what you want, you have to work with variables,
remembering the highest and lowest value.
Code:
Int sum = 0; 
Int aNumber = -1;
Int max = -999999;
Int min = 999999;

While (aNumber != 0)
{
	aNumber = JFB.getInt("Type a number, please (0 to stop):"); 
	if (aNumber != 0)
	{
		sum =  sum + aNumber;
		if (aNumber > max)
			max = aNumber;
		if (aNumber < min)
			min = aNumber;
	}
}

JFB.display("The highest number i s" + max );
JFB.display("The lowest number is " + min );
JFB.display("The sum is " + sum );

hope this is clear enough, let me know if not..

Reply With Quote
  #4  
Old November 5th, 2008, 12:24 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 47th Plane (28000 - 28499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 28,432 Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1Folding Points: 478881 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 1 Day 1 h 1 m 6 sec
Reputation Power: 2190
Quote:
Originally Posted by Glasgow_Man
cheers Shadow wizard code works! ..... ps you have exquisite taste in ladies my friend.
my pleasure Mr. Glasgow.. and you have good eyes to spot it.
feel free to stick around, if you liked that lady there's good chance
you would like other things in our Lounge.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Highest/Lowest Int values


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





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