Results 1 to 2 of 2
  1. #1
    Adr
    Adr is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Sorting values using while loop

    Hey guys.
    I've been asked to make a prgram that will ask for 5 numbers and display back the numbers in ascending order.
    I have managed to do it using for loop but I am required to use while loop. Can anyone help me get on track?
    I really am not familiar with while loop since i'm mainly into for loops

    Java Code:
    package Ascending_WhileLoop;
    
    import java.util.Scanner;
    
    
    public class Ascending_WhileLoop {
        public static void main(String[] args) 
        {
            Scanner s = new Scanner(System.in);
            int[] num = new int[5];       
            System.out.println("Give me 5 numbers: ");
            for(int x=0; x<5; x++)
            {
                num[x] = s.nextInt();  
            }                    
        }    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Sorting values using while loop

    A while(condition) statement loops until the condition goes false. Can you create a conditional expression that will go false when you want the loop to end?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Sorting a treemap by values?
    By Java Junior in forum New To Java
    Replies: 6
    Last Post: 03-19-2012, 04:54 PM
  2. Help Plz !! SORTING OID VALUES !!!
    By srinboss in forum New To Java
    Replies: 1
    Last Post: 12-03-2011, 11:06 PM
  3. Sorting string Array Values
    By Zerpol in forum New To Java
    Replies: 1
    Last Post: 01-14-2011, 08:08 AM
  4. Replies: 7
    Last Post: 09-23-2009, 08:28 PM
  5. sorting variable values in ascending order?
    By jeffrey in forum New To Java
    Replies: 0
    Last Post: 07-14-2009, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •