The Artima Developer Community
Sponsored Link

Java Answers Forum
please help me........

6 replies on 1 page. Most recent reply: Dec 4, 2005 10:38 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
rey

Posts: 10
Nickname: zerocoal
Registered: Sep, 2005

please help me........ Posted: Dec 1, 2005 10:10 PM
Reply to this message Reply
Advertisement
We are ask to make a program that ask the user to input 10 numbers and store it in the array. The program will output the biggest number being inputed by the the user...
I've working for it rigth now but i cant find the rigth syntax to determine the biggest number..

Anyone could help me up.. Thanks a lot..

God bless you all...Good Day.. More Power...


rey

Posts: 10
Nickname: zerocoal
Registered: Sep, 2005

Re: please help me........ Posted: Dec 1, 2005 10:14 PM
Reply to this message Reply
This program will be using java...thanks a lot...

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: please help me........ Posted: Dec 1, 2005 10:50 PM
Reply to this message Reply
int largeNum = 0;
for(int i =0; i < your_array.length; i++){
   if(your_array[i] > largeNum){
      largeNum = your_array[i];
   }
}
//  At the end of this loop the variable
//  largeNum will hold the largest number in your_array.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: please help me........ Posted: Dec 3, 2005 4:44 PM
Reply to this message Reply
You could also use
largeNum = Math.max(your_array[i], largeNum);
instead of the if block.

Ravi Venkataraman

Posts: 80
Nickname: raviv
Registered: Sep, 2004

Re: please help me........ Posted: Dec 3, 2005 5:41 PM
Reply to this message Reply
In the if block solution proposed above, if all the numbers are less than 0, the program will output zero, which is not the desired answer.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: please help me........ Posted: Dec 4, 2005 10:35 PM
Reply to this message Reply
> In the if block solution proposed above, if all the
> numbers are less than 0, the program will output zero,
> which is not the desired answer.

Good point. Instantiate largeNum at the beginning to
Integer.MIN_VALUE;

int largeNum = Integer.MIN_VALUE;

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: please help me........ Posted: Dec 4, 2005 10:38 PM
Reply to this message Reply
Actually even better off, instantiate it to the first
Index in the array.
int largeNum = your_array[0];
//  Then the mentioned loop will take care of
//  the swaping...

Flat View: This topic has 6 replies on 1 page
Topic: Very simple question I am sure Previous Topic   Next Topic Topic: Java NIO JVM memory problems

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use