Find the Largest Number

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

Find the Largest Number

Postposted on Thu Sep 23, 2010 10:06 am

Hi, I am working on my assignment: The assignment is:

The process of finding the largest value (i.e., the maximum of a group of values) is used frequently computer applications. Write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.

Below is my code so far:

LargestValue

Code: Select all
import java.util.Scanner; //scanner class import declaration
public class LargestValue
{
public void determineLargestValue()
{
Scanner input = new Scanner(System.in);

int intCounter = 0;
int total = 0;
int number;
int largest;

System.out.println("Enter number: ");
largest = input.nextInt();

total += largest;

while (intCounter < 9)
{
System.out.println("Enter number: ");
number = input.nextInt();
if(number > largest)
{
largest = number;
}
total += number;
intCounter++;
}

}//end if

}//end while


System.out.printf("The total is : %d\n", total);
System.out.printf("\nThe largest of all 10 integers is: %d\n", largest, number);
}
}


LargestValueTest

Code: Select all
class LargestValueTest
{
public void main(String args[])
{
LargestValue LargestValue1 = new LargestValue();//create object of LargestValue class to call method
LargestValue1.determineLargestValue();//find the largest integer in 10
}//end main
}//end class
Last edited by mohdiqbal on Sat Sep 25, 2010 3:15 am, edited 1 time in total.
mohdiqbal
Gerbil In Training
 
Posts: 3
Joined: Thu Sep 16, 2010 7:02 am

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 10:50 am

What is this ? 8th grade comp sci ?

Use a for loop duh.

int MAX=GetNextValue; // the first value by default is the max
for(int i=0;i < COUNTER;i++){
int temp=GetNextValue;
if( temp>MAX) MAX=temp;
}
GACKT ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
Dual nehalem Xeon e5520 / 16 GB DDR3 / GTX 280
mph_Ragnarok
Graphmaster Gerbil
 
Posts: 1315
Joined: Thu Aug 25, 2005 7:04 pm

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 11:00 am

mph_Ragnarok wrote:What is this ? 8th grade comp sci ?

Use a for loop duh.

int MAX=GetNextValue; // the first value by default is the max
for(int i=0;i < COUNTER;i++){
int temp=GetNextValue;
if( temp>MAX) MAX=temp;
}

Douchebag
Looking for Knowledge wrote:When drunk.....
I want to have sex, but find I am more likely to be shot down than when I am sober.
Heiwashin
Grand Gerbil Poohbah
 
Posts: 3027
Joined: Wed Dec 13, 2006 1:21 pm
Location: Denham Springs, LA

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 11:01 am

Ah, a good old bubble sort.
It is one of the blessings of old friends that you can afford to be stupid with them. Ralph Waldo Emerson.
Captain Ned
Global Moderator
Gold subscriber
 
 
Posts: 20270
Joined: Wed Jan 16, 2002 7:00 pm
Location: Vermont, USA

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 11:05 am

Captain Ned wrote:Ah, a good old bubble sort.

...huh? There are no bubble sorts here, nor should there be.

mohdiqbal: That looks fine for a program that's gathering input while acting on it. I hope your real code is indented, though!
Core i7 920, 3x2GB Corsair DDR3 1600, 80GB X25-M, 1TB WD Caviar Black, MSI X58 Pro-E, Radeon 4890, Cooler Master iGreen 600, Antec P183, opticals
SNM
Emperor Gerbilius I
 
Posts: 6206
Joined: Fri Dec 30, 2005 10:37 am

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 11:06 am

What problem(s) are you running into? We are not in the business doing your homework for you. Although most of us won't sound like a douchebag though.
Image
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
Flying Fox
Gerbil God
 
Posts: 24417
Joined: Mon May 24, 2004 2:19 am

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 11:14 am

Wait, that's Java. Is it really supposed to be written in Javascript, or was that a typo?
Core i7 920, 3x2GB Corsair DDR3 1600, 80GB X25-M, 1TB WD Caviar Black, MSI X58 Pro-E, Radeon 4890, Cooler Master iGreen 600, Antec P183, opticals
SNM
Emperor Gerbilius I
 
Posts: 6206
Joined: Fri Dec 30, 2005 10:37 am

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 1:09 pm

Captain Ned wrote:Ah, a good old bubble sort.

Bubble sort? No sorting necessary for this. It's either check for the max as the numbers are entered (most efficient), or check them after they're all entered (if you enter all the numbers in a single command).
Intel i7 860, Asus P7P55D Pro, 4x2GB Corsair XMS3 1600 (CMX4GX3M2A1600C9), EVGA GTX 560 Ti Superclocked
Seagate 7200.7 160GB, WD Caviar Black 640GB, WD Caviar Green 1TB, WD Caviar Green 2TB
Dell 2408WFP and Dell 2407WFP-HC for dual-24" goodness
emorgoch
Gerbil Elite
 
Posts: 690
Joined: Tue Mar 27, 2007 11:26 am
Location: Toronto, ON

Re: Find the Largest Number

Postposted on Thu Sep 23, 2010 8:03 pm

I'd use the douchebag's method. I'm not fluent with Javscript, but I might be able to give you some FORTRAN code that would do the job. :lol:
JustAnEngineer
Gerbil God
Gold subscriber
 
 
Posts: 15424
Joined: Sat Jan 26, 2002 7:00 pm
Location: The Heart of Dixie

Re: Find the Largest Number

Postposted on Fri Sep 24, 2010 12:00 am

SNM wrote:Wait, that's Java. Is it really supposed to be written in Javascript, or was that a typo?


It also said that he was to output it in XHTML... so unless he's writing a applet/servelet, I'd say that he's using the wrong programming language.
Image
Nitrodist
Grand Gerbil Poohbah
 
Posts: 3280
Joined: Wed Jul 19, 2006 1:51 am
Location: Minnesota

Re: Find the Largest Number

Postposted on Sat Sep 25, 2010 3:24 am

Guys, I have made me changes, my tasks are as follows:

"The process of finding the largest value is used frequently in computer applications (for eg: a program that determines the winner of a sales contest would input the number of units sold by each sales person. Teh salesperson who sells the most units wins the contest). Write a pesudocode program first and then write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.
mohdiqbal
Gerbil In Training
 
Posts: 3
Joined: Thu Sep 16, 2010 7:02 am

Re: Find the Largest Number

Postposted on Sat Sep 25, 2010 6:34 pm

Not sure what you want from us. We're not going to do your homework for you. We've already given you the process to go through to solve it. This is a simple program, shouldn't take more than 20 lines of code. Write them up and compile them. If you're still having trouble at that point, then come back, and we can help with the specific issues.
Intel i7 860, Asus P7P55D Pro, 4x2GB Corsair XMS3 1600 (CMX4GX3M2A1600C9), EVGA GTX 560 Ti Superclocked
Seagate 7200.7 160GB, WD Caviar Black 640GB, WD Caviar Green 1TB, WD Caviar Green 2TB
Dell 2408WFP and Dell 2407WFP-HC for dual-24" goodness
emorgoch
Gerbil Elite
 
Posts: 690
Joined: Tue Mar 27, 2007 11:26 am
Location: Toronto, ON

Re: Find the Largest Number

Postposted on Sun Sep 26, 2010 3:38 am

mohdiqbal wrote:Guys, I have made me changes, my tasks are as follows:

"The process of finding the largest value is used frequently in computer applications (for eg: a program that determines the winner of a sales contest would input the number of units sold by each sales person. Teh salesperson who sells the most units wins the contest). Write a pesudocode program first and then write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.


From your posts, it's clear that you're a beginner (not hating on you here). What specifically are you having trouble with? You are creating classes and putting in methods that could all be done within the main method which may be confusing you as to how these programs should be created in that it's another layer of complexity that isn't needed at this point.

Were you the author of that code you posted? Nothing wrong with studying code to get your self familiar, but if you're having trouble with something like this then perhaps you could look up the official Java tutorials which are very well written, post something more specific about what you're having trouble with or perhaps you need some 1-on-1 tutoring with a classmate/professor/tutor.
Image
Nitrodist
Grand Gerbil Poohbah
 
Posts: 3280
Joined: Wed Jul 19, 2006 1:51 am
Location: Minnesota


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 2 guests