Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2006, 07:04 AM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array beginner problem

How do i search the biggest integer in an array of say 5 elements and print them from the biggest to the smallest. my sample code is here
Code:
public static void main (String[] args)
     {
       int[] numbers=new int[5];
        int i;
        int temp = numbers[0];
        for(i=0;i<numbers.length;i++)
        {
          numbers[i] = Keyboard.readInt("Enter Integer " + (i + 1)+ ": ");
        }
        for(i=0;i<numbers.length;i++)
        {
    if(numbers[i]>temp)
    temp=numbers[i];
}
}


 
Old February 9th, 2006, 05:51 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[quote]Originally posted by dboy
 How do i search the biggest integer in an array of say 5 elements and print them from the biggest to the smallest. my sample code is here
the Java API has exactly what you are looking for
look for Arrays (not Array) and find the sort method
Hope it helps







Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner to the book with problem Happy Tommy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 July 9th, 2007 01:09 AM
Problem for a beginner antoneath Beginning PHP 1 January 29th, 2007 09:13 AM
System.Threading timer problem for beginner (Windo erikmail C# 2005 1 June 8th, 2006 08:03 AM
Beginner problem PAZII Java Basics 4 February 1st, 2006 05:27 AM
A vb.net beginner problem kitsam VB.NET 2002/2003 Basics 0 August 23rd, 2004 03:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.